-
Notifications
You must be signed in to change notification settings - Fork 68
/
index.py
105 lines (93 loc) · 3.38 KB
/
index.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 tencentcloud.common.profile.http_profile import HttpProfile
from actions.wiseLoginService import wiseLoginService
from actions.autoSign import AutoSign
from actions.collection import Collection
from actions.workLog import workLog
from actions.pushKit import pushKit
from actions.utils import Utils
from time import sleep
import traceback
def main():
Utils.log("自动化任务开始执行")
config = Utils.getYmlConfig()
push = pushKit(config['notifyOption'])
httpProxy = config['httpProxy'] if 'httpProxy' in config else ''
for user in config['users']:
Utils.log(f"10s后开始执行用户{user['user'].get('username','默认用户')}的任务")
sleep(10)
# 执行任务
try:
msg = working(user, httpProxy)
ret = True
except Exception as e:
msg = f'[{e}]\n{traceback.format_exc()}'
ret = False
# 根据任务执行情况(ret和msg)进行推送和记录
ntm = Utils.getTimeStr()
if ret == True:
# 此处需要注意就算提示成功也不一定是真的成功,以实际为准
Utils.log(msg)
if 'SUCCESS' in msg:
msg = push.sendMsg(
'今日校园签到成功通知',
'服务器(V%s)于%s尝试签到成功!' % (config['Version'], ntm),
user['user'])
else:
msg = push.sendMsg(
'今日校园签到异常通知', '服务器(V%s)于%s尝试签到异常!\n异常信息:%s' %
(config['Version'], ntm, msg), user['user'])
else:
Utils.log("Error:" + msg)
msg = push.sendMsg(
'今日校园签到失败通知', '服务器(V%s)于%s尝试签到失败!\n错误信息:%s' %
(config['Version'], ntm, msg), user['user'])
Utils.log(msg)
Utils.log("自动化任务执行完毕")
def working(user, httpProxy):
Utils.log('正在获取登录地址')
wise = wiseLoginService(user['user'], httpProxy)
Utils.log('开始尝试登录账号')
wise.login()
sleep(1)
# 登陆成功,通过type判断当前属于 信息收集、签到、查寝
# 信息收集
if user['user']['type'] == 0:
# 以下代码是信息收集的代码
Utils.log('开始执行收集任务')
collection = Collection(wise, user['user'])
collection.queryForm()
collection.fillForm()
sleep(1)
msg = collection.submitForm()
return msg
elif user['user']['type'] in [1, 2, 3]:
# 以下代码是签到的代码
Utils.log('开始执行签到任务')
sign = AutoSign(wise, user['user'])
sign.getUnSignTask()
sleep(1)
sign.getDetailTask()
sign.fillForm()
sleep(1)
msg = sign.submitForm()
return msg
elif user['user']['type'] == 4:
# 以下代码是工作日志的代码
Utils.log('开始执行日志任务')
work = workLog(wise, user['user'])
work.checkHasLog()
sleep(1)
work.getFormsByWids()
work.fillForms()
sleep(1)
msg = work.submitForms()
return msg
# 阿里云的入口函数
def handler(event, context):
main()
# 腾讯云的入口函数
def main_handler(event, context):
main()
return 'Finished'
if __name__ == '__main__':
main()