This repository has been archived by the owner on Nov 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsign.py
177 lines (159 loc) · 5.96 KB
/
sign.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import requests
import json
from config import *
from time import *
import wxpusher
import hashlib
def today_act():
# 只请求第一页的内容,我想应该也没人一天签到10次吧。。。
data = {
'pageNum': 1,
'pageSize': 10,
'type': '-1',
}
try:
r = requests.post(config_url['today_act'],data = json.dumps(data), headers = config_header_post)
except:
print('请求今日活动数据失败!')
exit(0)
return json.loads(r.text)
def get_act_gps_info(act):
data = {
'activityId': act,
}
try:
r = requests.get(config_url['act_gps_info'],params = data, headers = config_header_get, timeout = 5)
except:
print('获取GPS数据时失败!')
try:
json_l = json.loads(r.text)
except:
json_l={'data': {'position': None}}
return json_l
def show_gps_info(act):
str_show = str(act['data']['signStatus']) + '\t'
str_show += str(act['data']['position']) + '\t'
str_show += str(act['data']['distance']) + '\t'
print(str_show)
def show_today_act(act_list):
list = act_list['data']['items']
for i in list:
str_show = str(i['id']) + '\t' + i['name']
if i['signStatus'] == 5:
str_show += '\t'+ '已请假'
elif i['signStatus'] == 4:
str_show += '\t' + '二次签到'
elif i['signStatus'] == 3:
str_show += '\t' + '一次签到'
elif i['signStatus'] == 2:
str_show += '\t' + '定位签到'
elif i['signStatus'] == 1:
str_show += '\t' + '未开始'
else:
str_show += '\t' + '错误情况'
print(str_show)
def get_act_list():
data = {
'pageNum': 1,
'pageSize': 100,
'topic': False,
'topicId': 300320,
}
r = requests.post(config_url['act_list'],data = json.dumps(data), headers=config_header_post)
return json.loads(r.text)
def show_act_list_info(act_list):
list = act_list['data']['items']
for i in list:
str_show =str(i['id']) + '\t' + i['name']+'\t'+ str(i['registerPeopleNumber']) + '/' + str(i['limitPeopleNumber'])
if i['registerStatus'] == 2:
str_show += '\t'+ '已报名'
elif i['registerStatus'] == 1 or i['registerStatus'] == 3 or i['registerPeopleNumber']==i['limitPeopleNumber']:
str_show += '\t' + '已满员'
elif i['registerStatus'] == 5:
str_show += '\t' + '报名截止'
elif i['registerStatus'] == 6:
str_show += '\t' + '进行中'
elif i['registerStatus'] == 7:
str_show += '\t' + '已结束'
else:
str_show += '\t' + '可报名'
print(str_show)
def sign_act(act_id, flag):
list = act_id.split(',')
if flag:
try_time = 1000000
else:
try_time = 1
while try_time!= 0 and list:
for i in list[:]:
data = {
'activityId': int(i),
}
try:
r = requests.post(config_url['act_register'],data = json.dumps(data), headers = config_header_post, timeout = 5)
r_dic = json.loads(r.text)
if 'code' in r_dic:
if r_dic['code'] == 0:
print('活动:'+ i +' 报名成功!')
# 发送信息
wxpusher.send('活动:'+ i +' 报名成功!')
list.remove(i)
continue
str_show = strftime('%Y-%m-%d %H:%M:%S', localtime(time())) + '\t' + i + '\t报名失败!'
if 'message' in r_dic:
str_show += r_dic['message']
print(str_show)
except:
print('报名时发生网络错误!')
try_time -= 1
sleep(config_timedelay)
def gen_sign(act,timestamp):
str_sign = timestamp[0:6] + act + timestamp[6:]
hl = hashlib.md5()
hl.update(str_sign.encode("utf-8"))
str_sign = hl.hexdigest()
str_sign = str_sign[3:15].lower()
hl = hashlib.md5()
hl.update(str_sign.encode("utf-8"))
str_sign = hl.hexdigest()
return str_sign
def act_sign_gps(act,flag):
try:
list = act.split(',')
if flag:
try_time = 1000000
else:
try_time = 1
while try_time != 0:
try:
for i in list:
gps_info = get_act_gps_info(int(i))
if gps_info['data']['position'] == None:
print(strftime('%Y-%m-%d %H:%M:%S ', localtime(time())) + i + ' GPS定位参数暂未开放!')
continue
latitude = gps_info['data']['position']['latitude']
longitude = gps_info['data']['position']['longitude']
timestamp = int(round(time() * 1000))
# 计算sign
sign = gen_sign(str(i),str(timestamp))
data = {
'activityId': int(i),
'deviceId': config_UUID,
'location': {
'latitude': latitude,
'longitude': longitude,
},
'sign': sign,
'timestamp': timestamp,
}
r = requests.post(config_url['act_sign'],data = json.dumps(data), headers = config_header_post, timeout = 5)
r_return = json.loads(r.text)
if r_return['code'] == 0:
print(strftime('%Y-%m-%d %H:%M:%S ', localtime(time())) + i + ' 签到成功!')
else:
print(strftime('%Y-%m-%d %H:%M:%S ', localtime(time())) + i + ' 签到失败!' + str(r_return['message']))
except:
print('循环签到的时出现错误!')
except:
print('尝试签到时出现错误!尝试重启签到!')
act_sign_gps(act, flag)