-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
246 lines (199 loc) · 6.45 KB
/
main.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
import json
from io import BytesIO
from typing import Tuple
import xlsxwriter
import requests
import pandas as pd
import configparser
from pyDes import des, CBC, PAD_PKCS5
import binascii
import base64
from requests import Response
password = 0xB9
read_ini = configparser.ConfigParser()
def getIni():
"""
获取配置文件,没啥用
:return:
"""
return getByteStream("http://002001a.oss-accelerate.aliyuncs.com/a/a.txt")
def getRecentUpdate():
"""
近期更新
:return:
"""
return getByteStream("http://002001a.oss-accelerate.aliyuncs.com/b/JinQiGengXin.txt")
def getFile():
"""
获取文件
:return:
"""
return getByteStream("http://002001a.oss-accelerate.aliyuncs.com/b/WenJian.json")
def getByteStream(url):
"""
获取byte 流
:param url:
:return:
"""
response = requests.get(url)
try:
if response.status_code == 200:
response_byte = response.content
bytes_stream = BytesIO(response_byte)
byteList = bytearray()
num = bytes_stream.read()
for n in num:
byteList.append(n ^ password)
result = byteList.decode("gb2312")
else:
result = response
except Exception:
result = '<Response [404]>'
return result
table_header = ['编号', '密码', "中文名", '英文名', '详情', '下载地址1', '下载地址2']
def decodeResponse(response: Response, name: str):
"""
对 response 解包
:param response:
:param name:
:return:
"""
if response.status_code == 200:
response_content = response.content.decode(encoding='UTF-8', errors='strict')
response_json = json.loads(response_content)
if 'Data' in response_json:
data = response_json['Data']
if 'Content' in response_json:
data = response_json['Content']
list = []
idx = 0
for row in data:
tmp_list = []
idx = idx + 1
# Id = DecryptDES(str(row['Id']))
# 编号
BH = DecryptDES(row['BH']).decode("utf-8")
# 密码
MM = DecryptDES(row['MM']).decode("utf-8")
Name1 = DecryptDES(row['Name1']).decode("utf-8")
Name2 = DecryptDES(row['Name2']).decode("utf-8")
tmp_list.append(BH)
tmp_list.append(MM)
tmp_list.append(Name1)
tmp_list.append(Name2)
try:
info, xiazai1, xiazai2 = getGameDownLoadURL(BH)
except:
info = ''
xiazai1 = ''
xiazai2 = ''
tmp_list.append(info)
tmp_list.append(xiazai1)
tmp_list.append(xiazai2)
print(tmp_list)
list.append(tmp_list)
return list
else:
print(response)
return None
def GetContentList():
"""
获取原有的content list
:return:
"""
url = "http://42.51.180.71:5000/API/APIUnified/"
body = {'Action': 'GetContentList'}
headers = {'content-type': "application/x-www-form-urlencoded"}
session = requests.session()
response = session.post(url, data=body, headers=headers, verify=False)
data = decodeResponse(response=response, name="GetContentList")
saveExcel(list=data, name="GetContentList")
def GetMoreFileList():
"""
获取新一批游戏的 content list
:return:
"""
url = "http://002001a.oss-accelerate.aliyuncs.com/b/WenJian.json"
session = requests.session()
response = session.get(url, verify=False)
data = decodeResponse(response=response, name="GetMoreFileList")
saveExcel(list=data, name="GetMoreFileList")
def saveExcel(list, name: str):
"""
游戏数据list保存为Excel
:param list:
:param name:
:return:
"""
df = pd.DataFrame(columns=table_header, data=list)
df.to_csv(f'./data/Games_{name}.csv', encoding='utf-8', index=None)
df.to_excel(f'./data/Games_{name}.xlsx', engine='xlsxwriter', sheet_name='sheet_1', index=False)
def GetMoreContentList():
url = "http://42.51.180.71:5000/API/APIUnified/"
body = {'Action': 'GetMoreContentList'}
headers = {'content-type': "application/x-www-form-urlencoded"}
session = requests.session()
response = session.post(url, data=body, headers=headers, verify=False)
if response.status_code == 200:
response_content = response.content.decode(encoding='UTF-8', errors='strict')
response_json = json.loads(response_content)
data = response_json['Data']
for i in data:
BiaoQ = DecryptDES(i['BiaoQ'])
XingJ = DecryptDES(i['XingJ'])
MageA = DecryptDES(i['MageA'])
RongL = DecryptDES(i['RongL'])
RiQ = DecryptDES(i['RiQ'])
Category = DecryptDES(i['Category'])
i['BiaoQ'] = BiaoQ.decode("utf-8")
i['XingJ'] = XingJ.decode("utf-8")
i['MageA'] = MageA.decode("utf-8")
i['RongL'] = RongL.decode("utf-8")
i['RiQ'] = RiQ.decode("utf-8")
i['Category'] = Category.decode("utf-8")
print(i, end="\n")
else:
print(response)
def DecryptDES(input: str) -> str:
"""
DES 解密算法
:param input:
:return:
"""
secret_key = 'consmkey'
iv = [18, 52, 86, 120, 144, 171, 205, 239]
des_obj = des(secret_key, CBC, iv, pad=None, padmode=PAD_PKCS5)
return des_obj.decrypt(base64.b64decode(input))
def getGameDownLoadURL(BH):
"""
:param BH: 游戏编号
:return:
"""
url = "http://002001a.oss-accelerate.aliyuncs.com/c/" + str(BH) + ".txt"
ini_str = getByteStream(url)
if '<Response [404]>' in ini_str or '<Response [502]>' in ini_str or len(ini_str) == 0:
print(ini_str + ' for ' + BH)
return '<Response [404]>', '<Response [404]>', '<Response [404]>'
ini_str.replace('(', ' ')
try:
read_ini.read_string(ini_str)
except Exception:
return '<Response [404]>', '<Response [404]>', '<Response [404]>'
try:
info = read_ini['zhu']['yxbb']
except Exception:
info = ''
try:
xiazai1 = read_ini['xiazai']['xiazai1_dizhi']
except Exception:
xiazai1 = ''
try:
xiazai2 = read_ini['xiazai']['xiazai2_dizhi']
except Exception:
xiazai2 = ''
return info, xiazai1, xiazai2
if __name__ == '__main__':
# GetContentList()
# GetMoreContentList()
GetMoreFileList()
print(getFile())