-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
76 lines (63 loc) · 2.3 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
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : Arthals
# @File : main.py
# @Time : 2024/08/10 03:06:58
# @Contact : zhuozhiyongde@126.com
# @Software: Visual Studio Code
import time
from datetime import datetime, timedelta
import yaml
from session import BarkNotifier, Session
# load env
with open("config.yaml", "r") as f:
data = yaml.safe_load(f)
def start(notifier=None):
print(f"{'[Start]':<15}: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
s = Session(config=data, notifier=notifier)
s.login()
try:
s.submit_all()
print(f"{'[Succeed]':<15}: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
if notifier:
notifier.send("All Succeed")
except AssertionError as e:
print(f"{'[Failed]':<15}: {e} {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
if notifier:
notifier.send(f"Failed: {e}")
if __name__ == "__main__":
print(f"{'[Schedule]':<15}: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
# 计算到第二天 00:00:00 的时间差
now = datetime.now()
tomorrow = (now + timedelta(days=1)).replace(
hour=0, minute=0, second=1, microsecond=0
)
wait_time = (tomorrow - now).total_seconds()
print(f"{'[Waiting]':<15}: {wait_time} s")
if data.get("auto", True):
# 自动获取 2FA 验证码不需要提前提醒
# 等待到第二天的 00:00:00 时刻
if data.get("bark", None):
notifier = BarkNotifier(data["bark"])
notifier.send("已启动自动预约脚本")
else:
notifier = None
time.sleep(wait_time)
else:
# 手动获取 2FA 验证码需要提前提醒
# 等待到第二天的 00:00:00 时刻
if data.get("bark", None):
notifier = BarkNotifier(data["bark"])
notifier.send("已启动自动预约脚本")
if wait_time > 30:
time.sleep(wait_time - 30)
notifier.send("请准备在 30 秒后输入验证码")
time.sleep(30)
else:
notifier.send("请立刻准备输入验证码,剩余时间已不足 30 秒")
time.sleep(wait_time)
else:
notifier = None
time.sleep(wait_time)
# 开始执行任务
start(notifier)