-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWkApi.py
125 lines (109 loc) · 3.02 KB
/
WkApi.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
import random
import string
import fake_useragent
import requests
import json
# 实例化 user-agent 对象
ua = fake_useragent.UserAgent()
cookies = ""
identifier = ""
def getTaskList(cid,pageNum):
headers = {
'User-Agent': ua.chrome,
'cookie': cookies,
}
params = (
('cid', str(cid)),
('pn', pageNum),
('rn', '20'),
('word', ''),
('tab', '1'),
)
response = requests.get('https://cuttlefish.baidu.com/user/interface/getquerypacklist', headers=headers,
params=params)
return response.text
def getTaskRand():
headers = {
'User-Agent': ua.chrome,
'cookie': cookies,
}
response = requests.get('https://cuttlefish.baidu.com/user/interface/gettargetranking', headers=headers)
return response.text
def getUserInfo():
headers = {
'User-Agent': ua.chrome,
'cookie': cookies,
}
params = (
('_wkts_', '1679410018416'),
)
response = requests.get('https://cuttlefish.baidu.com/ndecommtob/fetchmain', headers=headers, params=params)
return response.text
# 3
def addUploadFile(md5sum,taskName,token,taskId,docId):
headers = {
'User-Agent': ua.chrome,
'cookie': cookies,
'Content-Type': 'application/json',
}
data = json.dumps({
"need_process_doc_info_list": {
docId: {
"title": taskName,
"summary": "",
"tag_str": "",
"flag": 28,
"cid1": 0,
"cid2": 0,
"cid3": 0,
"cid4": 0,
"file_md5sum": md5sum,
"fold_id": "1661665301",
"adoptStatus": 0,
"downloadable": 1,
"target_product_source": 1
}
},
"token": token,
"target_product_source": 1,
"query_id": taskId
})
response = requests.post('https://cuttlefish.baidu.com/ndecommtob/api/doc/upload/addpublicdoc', headers=headers,
data=data)
return response
# 1
def getPreviewfile(filename,token,fileSize):
headers = {
'User-Agent': ua.chrome,
'cookie': cookies
}
data = {
'filename':filename,
'identifier': identifier,
'totalSize': fileSize,
'file_ext': 'docx',
'token': token,
'isMajorTask': '1'
}
response = requests.post('https://cuttlefish.baidu.com/doc/newupload/previewfile', headers=headers, data=data)
return response
# 2
def getCompletefile(filename,identifier,fileTotal,token):
headers = {
'User-Agent': ua.chrome,
'cookie': cookies
}
data = {
'filename': filename,
'identifier': identifier,
'totalSize':fileTotal,
'file_ext': 'docx',
'token': token
}
response = requests.post('https://cuttlefish.baidu.com/doc/newupload/completefile', headers=headers, data=data)
def generate_identifier(length=32):
# 生成包含大小写字母和数字的字符集
chars = string.ascii_letters + string.digits
# 从字符集中随机选择32个字符,拼接成一个字符串
identifier = ''.join(random.choice(chars) for _ in range(length))
return identifier