This repository has been archived by the owner on Dec 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApi.py
179 lines (170 loc) · 7.93 KB
/
Api.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
178
179
import json
import time
import requests
from Notice import Notice
class Api:
def __init__(self, cookies):
self.cookies = cookies
self.expire = False
self.headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.5195.102 Safari/537.36 Language/zh wxwork/4.0.19 (MicroMessenger/6.2) WindowsWechat MailPlugin_Electron WeMail embeddisk",
"origin": "https://work.weixin.qq.com",
}
def getUserInfo(self) -> dict:
if self.expire:
return {}
n = Notice()
n.notice("info", "Auto Health Report Info", "Try to get user info")
url = f"https://work.weixin.qq.com/healthreport/getuserpartyinfo"
try:
r = requests.post(url,
headers=self.headers,
cookies=self.cookies,
data={"operatorid": self.cookies['wedrive_uin'],
"vids": self.cookies['wedrive_uin'],
"need_root_party": "true"})
res = json.loads(r.text)
if res['result']['errCode'] != 0:
self.expire = True
n = Notice()
n.notice("error", "Auto Health Report Error",
"Your cookies may be expired, please update your cookies.json file.")
return {}
except Exception as e:
print(e)
n = Notice()
n.notice("error", "Auto Health Report Error",
"Unknown Error occurred when getting user info, please copy the error information and make a new issue to me")
return {}
return res['data']
def getReportList(self) -> dict:
url = "https://work.weixin.qq.com/healthreport/healthformlist"
try:
r = requests.post(url, headers=self.headers, cookies=self.cookies, data={"source": "0"})
res = json.loads(r.text)
if res['result']['errCode'] != 0:
n = Notice()
n.notice("error", "Get Report Lists Error", "I'll tried it later.")
time.sleep(5)
return self.getReportList()
except Exception as e:
print(e)
n = Notice()
n.notice("error", "Get Report Lists Error",
"Unknown Error occurred when getting report lists, please copy the error information and make a new issue to me")
return {}
return res['data']
def getReportInfo(self, formId: str) -> dict:
"""
:param formId: 报告Id, 存于json/data.json中
:return dict: 报告信息
"""
url = f"https://work.weixin.qq.com/healthreport/share?_t={time.time()}&f=json&form_id={formId}{int(time.time()) - int(time.time() - time.timezone) % 86400}"
try:
r = requests.post(url, headers=self.headers, cookies=self.cookies)
res = json.loads(r.text)
if res['result']['errCode'] != 0:
n = Notice()
n.notice("error", "Get Report Info Error", "I'll tried it later.")
time.sleep(10)
return self.getReportInfo(formId)
except Exception as e:
print(e)
n = Notice()
n.notice("error", "Get Report Info Error",
"Unknown Error occurred when getting report info, please copy the error information and make a new issue to me")
return {}
return res['data']
def submitReport(self, answer: dict, formId: str, answerId: int = 1) -> bool:
"""
:param answer: 上报的答案
:param formId: 报告的Id
:param answerId: 已经提交过的报告Id, 默认为1时为初次提交, 否则为覆盖提交
:return bool: 是否提交成功
"""
url = "https://work.weixin.qq.com/healthreport/share?f=json"
data = {
"key": (None, ""),
"form_id": (None, f"{formId}{int(time.time()) - int(time.time() - time.timezone) % 86400}"),
"type": (None, "2"),
"form_reply": (None, json.dumps({"items": answer})),
"f": (None, "json"),
"source": (None, "hb_noticard"),
"vscode": (None, "null"),
}
if answerId != -1:
data["modify_answer_id"] = (None, answerId)
data['type'] = (None, "3")
try:
r = requests.post(url, headers=self.headers, cookies=self.cookies, files=data)
res = json.loads(r.text)
if res['result']['errCode'] != 0:
n = Notice()
n.notice("error", "Auto Health Report Error",
"Submit Error, please check your cookies and update cookies.json")
except Exception as e:
print(e)
n = Notice()
n.notice("error", "Auto Health Report Error",
"Unknown Error occurred when submitting the report, please copy the error information and make a new issue to me")
return False
return True
def getGeolocation(self) -> dict:
url = "https://apis.map.qq.com/ws/location/v1/ip?key=TKUBZ-D24AF-GJ4JY-JDVM2-IBYKK-KEBCU"
try:
r = requests.get(url, headers=self.headers)
res = json.loads(r.text)
if res['status'] != 0:
n = Notice()
n.notice("error", "Get Geolocation Error", "I'll tried it again.")
time.sleep(1)
return self.getGeolocation()
except Exception as e:
print(e)
n = Notice()
n.notice("error", "Get Geolocation Error",
"Unknown Error occurred when getting geolocation, please copy the error information and make a new issue to me")
return {}
return {"module": "geolocation",
"type": "ip",
"accuracy": 10000,
"adcode": res['result']['ad_info']['adcode'],
"nation": res['result']['ad_info']['nation'],
"province": res['result']['ad_info']['province'],
"city": res['result']['ad_info']['city'],
"lat": res['result']['location']['lat'],
"lng": res['result']['location']['lng'],
"addr": f"{res['result']['ad_info']['province']}{res['result']['ad_info']['city']}{res['result']['ad_info']['district']}({res['result']['location']['lng']},{res['result']['location']['lat']})",
"exportText": f"{res['result']['ad_info']['province']}{res['result']['ad_info']['city']}{res['result']['ad_info']['district']}({res['result']['location']['lng']},{res['result']['location']['lat']})"
}
def searchLocation(self, keyword: str, region: str = "南京", page: int = 1) -> tuple:
"""
:param keyword: 搜索关键字
:param region: 地区
:param page: 页码
:return tuple: 结果和页码
"""
url = "https://apis.map.qq.com/ws/place/v1/suggestion"
params = {
"key": "TKUBZ-D24AF-GJ4JY-JDVM2-IBYKK-KEBCU",
"keyword": keyword,
"region": region,
"page_size": 20,
"page_index": page,
"get_subpois": 0
}
try:
r = requests.get(url, headers=self.headers, params=params)
res = json.loads(r.text)
if res['status'] != 0:
n = Notice()
n.notice("error", "Search Location Error", "I'll tried it again.")
time.sleep(1)
return self.searchLocation(keyword, region, page)
except Exception as e:
print(e)
n = Notice()
n.notice("error", "Search Location Error",
"Unknown Error occurred when searching location, please copy the error information and make a new issue to me")
return ()
return res['data'], res['count']