-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
136 lines (110 loc) · 3.12 KB
/
main.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/python3
import datetime
import os
import time
from typing import List
import click
import schedule
import cube as p_cube
import one as p_one
import bot_reply
def gen_time_str_list(s_time: datetime.time, e_time: datetime.time, interval: datetime.timedelta) -> List[str]:
"""
生成时间序列,精确到分钟
:param s_time:
:param e_time:
:param interval:
:return:
"""
start_seconds = s_time.hour * 60 * 60 + s_time.minute * 60 + s_time.minute
end_seconds = e_time.hour * 60 * 60 + e_time.minute * 60 + e_time.minute
for i in range(start_seconds, end_seconds, interval.seconds):
schedule_time = datetime.datetime.fromtimestamp(i, tz=datetime.timezone(datetime.timedelta(hours=0))).strftime(
'%H:%M')
yield schedule_time
@click.group()
def cli():
pass
@cli.command()
def schedule_tasks():
"""
配置定时任务
"""
click.echo('配置定时任务')
# 班级群 班级魔方打卡
for t in gen_time_str_list(datetime.time(20, 00), datetime.time(23, 46), datetime.timedelta(minutes=15)):
schedule.every().days.at(t).do(os.system, 'python3 main.py cube alert')
# 班级群 小one易打卡
for t in gen_time_str_list(datetime.time(8, 00), datetime.time(17, 00), datetime.timedelta(minutes=60)):
schedule.every().days.at(t).do(os.system, 'python3 main.py one alert')
# 下午17点后增加小one易打卡提醒频率
for t in gen_time_str_list(datetime.time(17, 00), datetime.time(23, 40), datetime.timedelta(minutes=15)):
schedule.every().days.at(t).do(os.system, 'python3 main.py one alert')
# 小one易辅导员提醒
schedule.every().days.at('17:00').do(os.system, 'python3 main.py one counselor')
# 小one易自动打卡
schedule.every().days.at('07:40').do(os.system, 'python3 main.py one punch')
# 班级魔方自动打卡
schedule.every().days.at('20:15').do(os.system, 'python3 main.py cube punch')
schedule.every().days.at('20:40').do(os.system, 'python3 main.py cube punch')
all_jobs = schedule.get_jobs()
print(all_jobs)
while True:
schedule.run_pending()
time.sleep(1)
@cli.command()
def process_message():
"""
接收处理机器人消息
"""
bot_reply.app.run()
@cli.group()
def one():
"""
小one易相关操作
"""
pass
@one.command()
def punch():
"""
小one易打卡
"""
click.echo('小one易打卡')
p_one.auto_punch()
@one.command()
def alert():
"""
小one易打卡提醒
"""
click.echo('小one易打卡提醒')
p_one.alert_class()
@cli.group()
def cube():
"""
班级魔方相关操作
"""
pass
@cube.command()
def alert():
"""
班级魔方打卡提醒
"""
click.echo('班级魔方打卡提醒')
p_cube.alert_class()
@one.command()
def counselor():
"""
向辅导员发送提醒消息
"""
p_one.alert_counselor()
@cube.command()
def punch():
"""
班级魔方打卡
"""
click.echo('班级魔方打卡')
p_cube.auto_punch()
if __name__ == '__main__':
# process_message()
# p_one.alert_counselor()
cli()