-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheduler.py
105 lines (92 loc) · 3.47 KB
/
scheduler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from datetime import datetime
from .utils import *
from .api import *
from .oldapi import *
from . import sv_cron as sv, sv_lt, files
from . import bot
from nonebot import on_startup
from hoshino.config import SUPERUSERS
import random
async def report_to_su(sess, msg_with_sess, msg_wo_sess):
if sess:
await sess.send(msg_with_sess)
else:
global bot
sid = bot.get_self_ids()
if len(sid) > 0:
sid = random.choice(sid)
await bot.send_private_msg(self_id=sid, user_id=SUPERUSERS[0], message=msg_wo_sess)
@sv.scheduled_job('interval', minutes=120) # 2小时进行1次爬虫
async def loadMsg():
try:
await getNiuKe()
except Exception as e:
sv.logger.exception(e)
await report_to_su(None, f'Error: {e}', f'牛客比赛信息定时更新时遇到错误:\n{e}')
try:
await getContest()
except Exception as e:
sv.logger.exception(e)
await report_to_su(None, f'Error: {e}', f'比赛信息定时更新时遇到错误:\n{e}')
try:
await getNiuKeSchool()
except Exception as e:
sv.logger.exception(e)
await report_to_su(None, f'Error: {e}', f'牛客高校比赛信息定时更新时遇到错误:\n{e}')
try:
await getLeetcodeDaily()
except Exception as e:
sv.logger.exception(e)
await report_to_su(None, f'Error: {e}', f'leetcode每日一题定时更新时遇到错误:\n{e}')
@sv_lt.scheduled_job('cron', hour='4', minute='00', jitter=00)
async def luogunews():
try:
await getLuoguYuebao()
except Exception as e:
sv.logger.exception(e)
await report_to_su(None, f'Error: {e}', f'洛谷日报定时更新时遇到错误:\n{e}')
@sv_lt.scheduled_job('cron', hour='8', minute='00', jitter=00)
async def leetcodeDaily():
await getLeetcodeDaily()
data = load_json("leetcode_daily.json")
msg = get_problem_remind(data['id'], data['title'], data['date'], data['difficulty'], data['url'], data['content'])
await sv_lt.broadcast(msg, "leetcode_daily")
@sv.scheduled_job('interval', minutes=1)
async def CodingCheck ():
global bot
global group_list
now = datetime.now()
for contest_file in files:
contests = await get_upcoming_contest(contest_file)
if not contests:
continue
for info in contests:
name = info['name']
start_time = datetime.strptime(info['start_time'], "%Y-%m-%d %H:%M")
end_time = datetime.strptime(info['end_time'], "%Y-%m-%d %H:%M")
link = info['link']
delta = start_time - now
if 3540 < delta.total_seconds() <= 3600:
msg = get_contest_remind(name, start_time, end_time, link)
await sv.broadcast(msg, "contest_remaind")
@on_startup
async def init():
try:
await do_flush()
except Exception as e:
sv.logger.exception(e)
await report_to_su(None, f'Error: {e}', f'初始化比赛信息时遇到错误:\n{e}')
@sv.on_fullmatch('flush', only_to_me = True)
async def flush(bot, ev):
try:
await do_flush()
except Exception as e:
sv.logger.exception(e)
await bot.finish(ev, f'Error: {e}')
await bot.finish(ev, "ok")
async def do_flush():
await getContest()
await getNiuKe()
await getNiuKeSchool()
await getLeetcodeDaily()
await getLuoguYuebao()