This repository has been archived by the owner on Nov 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
study_20230702.py
398 lines (336 loc) · 13.9 KB
/
study_20230702.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
import asyncio
import json
import time
import urllib.parse
from datetime import datetime
import xlrd
from numpy.core.defchararray import isdigit
from rich.progress import Progress
from tqdm import tqdm
import config
import requests
from rich import print as print
from rich import pretty
from rich import print as print
from rich.console import Console as console
from rich.table import Table
pretty.install()
requests.packages.urllib3.disable_warnings()#清除出现https安全警告
tittle = '''
####################################################################
___====-_ _-====___
_--^^^#####// \\#####^^^--_
_-^##########// ( ) \\##########^-_
-############// |\^^/| \\############-
_/############// (@::@) \############\_
_/#############(( \\// ))#############\_
-###############\\ (oo) //###############-
-#################\\ / VV \ //#################-
-###################\\/ \//###################-
_#/|##########/\######( /\ )######/\##########|\#_
|/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \|
` |/ V V ` V \#\| | | |/#/ V ' V V \| '
` ` ` ` / | | | | \ ' ' ' '
( | | | | )
__\ | | | | /__
(vvv(VVV)(VVV)vvv)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
神兽保佑 永无BUG
github:https://github.com/ygxiuming/QN-big-study
使用声明
本源代码是本人利用时间的写成,《免费》向编程爱好者学习使用!
本源禁止使用商业非法用途!
本源代码无任何恶意代码!所造成的损失等概与本人无关
使用编译本原始码即取代同意上述声明
——————修明
####################################################################
'''
import threading
# 定义一个线程类
class MyThread(threading.Thread):
def __init__(self, func, args):
threading.Thread.__init__(self)
self.func = func
self.args = args
def run(self):
self.func(*self.args)
def get_mes(pid):
url = f"http://www.jxqingtuan.cn/pub/pub/vol/config/organization?pid={pid}"
payload = {}
headers = {
'Host': 'www.jxqingtuan.cn',
'Content-Type': 'application/json;charset=UTF-8',
'Accept-Encoding': 'gzip, deflate',
'Connection': 'keep-alive',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'User-Agent': 'Mozilla/5.0 (iPad; CPU OS 16_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.27(0x18001b21) NetType/WIFI Language/zh_CN',
'Referer': 'http://www.jxqingtuan.cn/html/h5_index.html',
'Accept-Language': 'zh-CN,zh-Hans;q=0.9',
'X-Requested-With': 'XMLHttpRequest',
}
response = requests.request("GET", url, headers=headers, data=payload)
# print(response.text)
print("")
response = json.loads(response.text)
response = response["result"]
if len(response) == 0 :
print(f"当前选择选项PID为 {pid}")
return {},0
else:
# print = response
response_len = len(response)
k = {}
num = []
for i in response:
tittle = i['title']
id = i['id']
k["{}".format(tittle)] = id
num = list(k.values())
return k,num
def id_getinfo():
list_tittle = {"团省委机关": "N0017",
"省直属单位团委": "N0016",
"省属本科院校团委": "N0013",
"非省属本科院校团委": "N0014",
"高职专科院校团委": "N0015",
"南昌市": "N0002",
"九江市": "N0003",
"景德镇市": "N0004",
"萍乡市": "N0005",
"新余市": "N0006",
"鹰潭市": "N0007",
"赣州市": "N0008",
"宜春市": "N0009",
"上饶市": "N0010",
"吉安市": "N0011",
"抚州市": "N0012"
}
#第一级
t=0
while(1):
if t == 0:
i = 0
samp = list(list_tittle.values())
print("请输入相应序号!")
for k in list_tittle:
print(str(i + 1) + "." + str(k) + ":" + str(list_tittle[k]))
i = i + 1
t = input("请输入对应序号:")
if isdigit(t):
t = int(t)
else:
break
pid = samp[t - 1]
elif t == 'q':
break
else:
list1,num = get_mes(pid)
i = 0
for k in list1:
print(str(i+1) + "." + str(k) + ":" + str(list1[k]))
i = i + 1
t = input("请输入对应序号(输入0重新查询,输入q退出查询!):")
if isdigit(t):
t = int(t)
else:
break
if t !=0 :
pid = num[t - 1]
else:
pass
def gettittle():
global datas
url = config.url['get_title']
res = requests.get(url,timeout=5).text
res = json.loads(res)["list"][0]
# print(res)
id = res["id"]
tittle = res["title"]
url = res["url"]
t = "第{}期".format(id) + tittle
print("第{}期".format(id) + "青年大学习标题:" + tittle + "\n" + "青年大学习学习链接:" + url)
return id, tittle, url
def get_person_info(token):
info = {}
url = config.url['get_person_info'] + token
response = requests.request("GET", url, headers=config.headers,timeout=5)
res = json.loads(response.text)
# print(res)
for key, value in res["vo"].items():
info[key] = value
# info['user_id'] = res['vo']['id']
# info['name'] = res['vo']['username']
# # address = res['vo']['address']
# info['zhibu'] = res['vo']['danwei'] + res['vo']['zhibu']
# info['openid'] = res['vo']['openid']
# info['score'] = res['vo']['score']
# info['wxname'] = res['vo']['wxname']
# info['sex'] = res['vo']['sex']
# info['brithday'] = res['vo']['brithday']
# # print(res)
try:
user_id = res['vo']['id']
name = res['vo']['username']
return user_id, name, info
except : print("错误!!!")
def get_score_viery(token,userid,title,info):
url = f"http://www.jxqingtuan.cn/pub/pub/vol/classrecord/index?openid={token}&userId={userid}&page=1&pageSize=10"
response = requests.request("GET", url, headers=config.headers,timeout=5)
if len(json.loads(response.text)['vo']) > 0:
res = json.loads(response.text)['vo'][0]
# console.print_json(data = res)
study_tittle = res['title']
# print(res)
if title == study_tittle:
# console.print(f"[bold green]{study_tittle} 学习完成![/bold green]")
state = "success"
else:
# console.print("[bold red]Error:[/bold red] 学习失败!,请联系作者:[email protected]")
state = "false"
else:
console.print("[bold red]Error:[/bold red] 未查询到学习记录!")
state = "false"
table = Table(show_header=True, header_style="bold")
# 添加表头
table.add_column("标题", style="dim")
table.add_column("内容", style="dim")
# 添加数据行
for key,value in info.items():
table.add_row(str(key),str(value))
table.add_row("学习标题", str(study_tittle))
table.add_row("学习时间", str(res['addtime']))
table.add_row("学习状态", str(state))
table.add_row("仓库网址", str("https://github.com/ygxiuming/QN-big-study"))
table.add_row("作者邮箱", str("[email protected]"))
# 打印表格
console.print(table)
def addScoreInfo(token, userid,url):
payload = {
"check":1,
"type": 3,
'title':"青年大学习",
"url": url,
"openid":token,
"userId":userid
}
headers = {
'Host': 'www.jxqingtuan.cn',
'Connection': 'keep-alive',
'Content-Length': '195',
'User-Agent': 'Mozilla/5.0 (Linux; Android 13; 23013RK75C Build/TKQ1.220905.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/107.0.5304.141 Mobile Safari/537.36 XWEB/5127 MMWEBSDK/20230604 MMWEBID/8031 MicroMessenger/8.0.38.2400(0x28002639) WeChat/arm64 Weixin NetType/WIFI Language/zh_CN ABI/arm64',
'openid': f'{token}',
'content-type': 'application/x-www-form-urlencoded',
'Accept': '*/*',
'Origin': 'http://www.jxqingtuan.cn',
'X-Requested-With': 'com.tencent.mm',
'Referer': f'http://www.jxqingtuan.cn/html/?accessToken={token}',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
}
encoded_payload = urllib.parse.urlencode(payload)
response = requests.request("POST", url = config.url['addscore'], headers=headers, data=encoded_payload,timeout=5)
print(response.text)
def QN_study(accessToken,token,id,nid,name,subOrg):
if len(subOrg) > 0:payload = {"accessToken": token,"course": id, "nid": nid, "cardNo": name, "subOrg": subOrg}
else:payload = {"accessToken": token,"course": id,"subOrg": "0","nid": nid,"cardNo": name}
payload = json.dumps(payload)
print(payload)
url = f"http://www.jxqingtuan.cn/pub/pub/vol/volClass/join?accessToken={accessToken}"
headers = config.headers
headers['openid'] = accessToken
response = requests.request("POST", url, headers=headers, data=payload,timeout=5)
print(response.text)
# res = json.loads(response.text)
if response.status_code == 200:
return '青年大学习学习成功!!!'
else:
text = ("提交大学习导致未知错误:" + response.text)
return text
def get_excel_info():
data = []
data_excel = xlrd.open_workbook('名单.xls')
table = data_excel.sheets()[0] # 通过索引顺序获取
nid_list = table.col_values(colx=0)
for i in range(1, len(nid_list)):
info = {}
text = table.row_values(i, start_colx=0, end_colx=None)
if text[2] == '':
sub = '四级组织'
else:
sub = '三级组织'
info['nid'] = text[0]
info['name'] = text[1]
info['subOrg'] = text[2]
info['token'] = text[3]
data.append(info)
return data
def main(token,nid,name,id,tittle,subOrg,url):
global error
print(f'{tittle}\nNID: {nid}\nName: {name}\n{subOrg}\n')
try:
QN_study(token, token,id,nid,name,subOrg)
userid, name,info = get_person_info(token)
addScoreInfo(token, userid,url)
get_score_viery(token, userid,tittle,info)
except Exception as e:
print("main 函数出现错误,错误为:",e)
info_list = {}
info_list['nid'] = nid
info_list['name'] = name
info_list['error'] = e
error.append(info_list)
if __name__ == '__main__':
console = console(color_system='256', style=None)
console.rule("江西青年大学习学习交流脚本")
print(tittle)
agree = int(input("是否同意以上声明,同意(请输入1),不同意(请输入0) :"))
error = []
model = '''
####################################################################
使用说明:
将名单.xlsx表格与该程序放置同一目录下,填写相关学习名单信息,
其中组织代码pid可通过该程序的模块1可查询,如果是三级组织需填写班级
信息,若是四级组织不要填写班级信息空着即可。
填写完成之后运行该程序的模块2即可批量学习!
若出现问题可前往以下网址提交issu
https://github.com/ygxiuming/QN-big-study
####################################################################
1.青年大学习组织id查询
2.青年大学习开始批量学习
####################################################################
'''
if agree == 0:
print("请关闭软件,出门右走谢谢!")
else:
while 1:
print(model)
mod = int(input("请输入选择模式序号:"))
if mod == 1 :
id_getinfo()
print("已返回模块选择界面!!!")
else:
# data = get_excel_info()
# id, tittle, url = gettittle()
# for i in tqdm(data):
# token = i['token']
# nid = i['nid']
# name = i['name']
# subOrg = i['subOrg']
# console.rule()
# main(token,nid,name,id,tittle,subOrg,url)
# console.rule()
data = get_excel_info()
id, tittle, url = gettittle()
processes = []
for i in tqdm(data):
token = i['token']
nid = i['nid']
name = i['name']
subOrg = i['subOrg']
thread = threading.Thread(target=main, args=(token, nid, name, id, tittle, subOrg,url))
processes.append(thread)
thread.start()
# 等待线程完成
processes[-1].join()
print(error)
time.sleep(1000)