This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
0_org_check.py
115 lines (88 loc) · 4.1 KB
/
0_org_check.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
# encoding:utf-8
import json
import time
import requests
import config
import captcha
def get_code_info():
for try_cnt in range(config.CAPTCHA_FAIL_CNT):
# 获取image、UUID值
code_url = "https://wiki.0-sec.org/api/user/captchaImage"
code_image = requests.get(code_url)
json_data = json.loads(code_image.content)
try:
# 默认已是 base64 编码,不需要转换
cap_code = captcha.captcha_handle(json_data['data']['img'])
except (IndexError, NameError, TypeError):
cap_code = ''
if len(cap_code) == config.CAPTCHA_CHECK:
return json_data['data']['uuid'], cap_code
print("验证码识别抽风了, 重试第 " + str(try_cnt) + " 次ing...")
time.sleep(1.5)
continue
sign_error('重试了' + str(config.CAPTCHA_FAIL_CNT) + '次, 验证码识别真的抽风了, 退出...')
def login(_captcha_uuid, _captcha_code):
url = "https://wiki.0-sec.org/api/user/login"
for _ in range(config.CAPTCHA_FAIL_CNT):
login_data = {
"account": config.ZERO_USER, "password": config.ZERO_PASSWD,
"code": _captcha_code, "uuid": _captcha_uuid
}
data_json = json.dumps(login_data)
logins = requests.post(url=url, headers=config.HTTP_HEADER, data=data_json)
res_login = json.loads(logins.content)
login_msg = res_login.get('message') or ''
if '验证码错误' in login_msg:
_captcha_uuid, _captcha_code = get_code_info()
continue
if '用户名或密码不正确' in login_msg:
sign_error('检查一下下帐号密码有没有错喔!')
try:
# 登录成功后获取到的 token
return res_login['data']['token']
except TypeError:
print('****** 脱敏后发送此部分数据到 issue ******\n' + res_login + '\n****** 脱敏后发送此部分数据到 issue ******')
sign_error('零组文库登录接口返回数据异常')
sign_error('可以试试 Re-run-jobs,如果还不行就是验证码识别抽风了...免费的是有极限的 (')
# PushPlus Push 消息推送
def push_plus_push(token, sign_info):
text = "{}".format(sign_info)
url = "https://www.pushplus.plus/send?token={0}&title={1}&content={2}&template={3}".format(
token, "零组文库签到", text, "html"
)
try:
ret = requests.get(url)
print("pushplus: " + ret.text)
except Exception:
print('pushplus 推送接口访问异常, 请检查接口可达性或token是否正常')
def sign(token):
headers = {'Zero-Token': token}
url = "https://wiki.0-sec.org/api/profile"
old_sign_data_json = requests.get(url=url, headers=headers)
old_sign_data_credit = json.loads(old_sign_data_json.content)['data']['credit']
url1 = "https://wiki.0-sec.org/api/front/user/sign"
requests.post(url=url1, headers=headers)
new_sign_data_json = requests.get(url=url, headers=headers)
new_sign_data_credit = json.loads(new_sign_data_json.content)['data']['credit']
# 消息推送
if len(config.PLUSPUSH) != 0:
push_plus_push(config.PLUSPUSH, '签到成功, 当前积分为: ' + str(new_sign_data_credit))
if new_sign_data_credit > old_sign_data_credit:
print("签到成功,当前积分为:", new_sign_data_credit)
else:
print("兄弟,你已经签到过了,你的积分为:", new_sign_data_credit)
def check_input(*args):
for v in args:
if len(v) == 0:
sign_error('请检查 ZERO_USER ZERO_PASSWD API_KEY API_SECRET 四个字段是否存在')
if len(v) > 128:
sign_error('帐号密码密钥太长啦...')
def sign_error(error_text):
# 这里写死常量, 防止不小心信息泄漏
push_plus_push(config.PLUSPUSH, '签到失败, 请到 Github Action 查看详细原因')
raise Exception(error_text)
if __name__ == '__main__':
check_input(config.ZERO_USER, config.ZERO_PASSWD, config.API_KEY, config.API_SECRET)
captcha_uuid, captcha_code = get_code_info()
tokens = login(captcha_uuid, captcha_code)
sign(tokens)