-
Notifications
You must be signed in to change notification settings - Fork 2
/
daily_post.py
57 lines (44 loc) · 1.61 KB
/
daily_post.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
from typing import Tuple
import time
from argparse import ArgumentParser
from apscheduler.schedulers.blocking import BlockingScheduler
from health_post import do_report
from utils.login import login
from utils.email import send_email
import config
def login_report(user_config: Tuple):
ss = login(user_config[0], user_config[1])
if ss:
return do_report(ss)
def do_job(try_num: int):
print(
f'start...Local Time: {time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}'
.center(50, '-'))
for user_config in config.user_list:
print(user_config)
count = 0
while count < try_num and not login_report(user_config):
count += 1
if count < try_num:
send_email(**config.sender_cfg,
receivers=[user_config[2]],
messageText='Daily post Succeed!')
else:
send_email(**config.sender_cfg,
receivers=[user_config[2]],
messageText='Daily post Failed...qwq')
print('end')
def daily_do_jobs(try_num: int):
scheduler = BlockingScheduler()
scheduler.add_job(do_job, 'cron', hour=config.daily_time[0], minute=config.daily_time[1], args=[try_num])
scheduler.start()
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument('--once', '-o', action='store_true')
parser.add_argument('--try_num', '-t', default=3, type=int)
args = parser.parse_args()
print('Only do once' if args.once else 'Do it every day')
if args.once:
do_job(args.try_num)
else:
daily_do_jobs(args.try_num)