Spaces:
Sleeping
Sleeping
come
commited on
Commit
·
7db66af
1
Parent(s):
fc87e49
Update app.py
Browse files
app.py
CHANGED
@@ -3,15 +3,17 @@ import re
|
|
3 |
import json
|
4 |
|
5 |
import gradio as gr
|
|
|
|
|
6 |
def ReRequestUrl(url):
|
7 |
try:
|
8 |
if 'gravity' not in url:
|
9 |
return ''
|
10 |
-
Newurl='http://'+re.findall('http://(.*?)"',url)[0]
|
11 |
|
12 |
-
signed=re.findall('sign=(.*?)&',Newurl)[0]
|
13 |
|
14 |
-
FinnalUrl=Newurl.replace(signed,'fsdfgasdgf34578348jiren')
|
15 |
|
16 |
req = requests.get(FinnalUrl)
|
17 |
|
@@ -20,157 +22,169 @@ def ReRequestUrl(url):
|
|
20 |
except:
|
21 |
return ''
|
22 |
|
|
|
23 |
def GetList(data):
|
24 |
-
if len(data)==0:
|
25 |
-
newJson={}
|
26 |
-
newJson['type']='string'
|
27 |
return newJson
|
28 |
else:
|
29 |
-
data=data[0]
|
30 |
-
if type(data)==dict:
|
31 |
-
newItemjson=GetJson(data)
|
32 |
|
33 |
return newItemjson
|
34 |
|
35 |
|
36 |
def GetJson(data):
|
37 |
-
newJson={}
|
38 |
-
newJson['type']='object'
|
39 |
-
newJson['required']=[]
|
40 |
-
propertiesJson={}
|
41 |
-
for key,value in data.items():
|
42 |
-
|
43 |
-
if type(value) ==str:
|
44 |
-
propertiesJson[key]={'type':'string'}
|
45 |
-
elif type(value) ==int:
|
46 |
propertiesJson[key] = {'type': 'number'}
|
47 |
elif type(value) == list:
|
48 |
-
newListJson={}
|
49 |
-
newListJson['type']='array'
|
50 |
newListJson['items'] = GetList(value)
|
51 |
-
propertiesJson[key]=newListJson
|
52 |
elif type(value) == dict:
|
53 |
-
newListJson=GetJson(value)
|
54 |
propertiesJson[key] = newListJson
|
55 |
else:
|
56 |
-
print(value,type(value))
|
57 |
propertiesJson[key] = None
|
58 |
|
59 |
-
newJson['properties']=propertiesJson
|
60 |
return newJson
|
61 |
-
|
|
|
62 |
def gerTtr(typeStr):
|
63 |
-
str=str(typeStr)
|
64 |
-
NewStr=re.findall('<class \'(.*?)\'>',str)
|
65 |
return NewStr
|
66 |
|
67 |
-
def excuJson(html,jsonOuputPath):
|
68 |
|
69 |
-
|
|
|
70 |
|
71 |
-
data=json.loads(html)
|
72 |
-
#print(data)
|
73 |
-
#newJson==GetJson(data)
|
74 |
|
75 |
-
listL=[]
|
76 |
-
dictL={}
|
77 |
-
jsonOutput=GetJson(data)
|
78 |
print(jsonOutput)
|
79 |
-
json.dump(jsonOutput,open(jsonOuputPath,'w',encoding='utf-8')
|
80 |
|
81 |
-
|
82 |
-
print(type('uk123')==str)
|
83 |
print(type(listL))
|
84 |
print(type(1))
|
85 |
print(type(dictL))
|
86 |
return jsonOutput
|
87 |
|
|
|
88 |
def getHtml(url):
|
89 |
try:
|
90 |
-
headers={
|
91 |
-
|
92 |
-
|
|
|
93 |
return res.text
|
94 |
else:
|
95 |
-
print('Error Code:'+str(res.status_code))
|
96 |
return ''
|
97 |
except Exception as e:
|
98 |
print(e)
|
|
|
|
|
99 |
def getITP(Request):
|
100 |
-
#Request = 'curl -H "Host: pre-release.gravity.place" -H "User-Agent: okhttp/3.12.13" --compressed "http://pre-release.gravity.place/gravity/metaverse/starUserList?country=CN&product=gravity&star_id=23&sys_lang=ja&uwd=YRHBwL8DHv04H3JUkjFuiWFQgdmQxIy64bp7qHpU4JbPo1wW6IcEaMMp6LsT34op%0A&app_version=7.7.0&user_country=CN&sign=31caf01c033f194abc5287df89ff80bb&source=star_detail&pkg=anonymous.sns.community.gravity&token=1QZVaDtlJ21T9CYEPRAKqC1X14y6xD5%252Bfetlx%252FTJE%252Bnl2lganNSgB9BSTNgdUCCN&languageV2=ja&referrer=Organic&zone=8&system_version=10&sdk_version=29&model=V2023A&device=android&brand=vivo&ts=1686842126"'
|
101 |
url = ReRequestUrl(Request)
|
102 |
html = getHtml(url)
|
103 |
jsonOuputPath = 'outputJson.json'
|
104 |
-
jsonOutput=excuJson(html, jsonOuputPath)
|
105 |
print(jsonOutput)
|
106 |
|
107 |
-
return url,showJson(jsonOutput)
|
|
|
108 |
|
109 |
def showJson(jsondata):
|
110 |
-
jsonStr=str(jsondata).replace(' ','').replace('\n','')
|
111 |
-
outPutJson=''
|
112 |
-
spaceCount=0
|
113 |
-
lines=[]
|
114 |
-
line=''
|
115 |
for i in range(len(jsonStr)):
|
116 |
-
char1=jsonStr[i]
|
117 |
|
|
|
|
|
|
|
118 |
|
119 |
-
|
120 |
-
spaceCount+=1
|
121 |
-
outPutJson=outPutJson+char1+'\n'
|
122 |
-
|
123 |
-
line+=char1+'\n'+ spaceCount*2*' '
|
124 |
lines.append(line)
|
125 |
-
line=''
|
126 |
-
elif char1 == '}' and i!=len(jsonStr)-1 and jsonStr[i+1]!=',':
|
127 |
spaceCount -= 1
|
128 |
-
outPutJson=outPutJson+'\n'+spaceCount*2*' '+char1
|
129 |
|
130 |
-
line += '\n'+spaceCount*2*' '+char1
|
131 |
lines.append(line)
|
132 |
line = ''
|
133 |
-
elif char1 == '}' and i!=len(jsonStr)-1 and jsonStr[i+1]==',':
|
134 |
spaceCount -= 1
|
135 |
-
outPutJson=outPutJson+'\n'+jsonStr[i+1]
|
136 |
-
|
137 |
|
138 |
-
line += '\n'+spaceCount*2*' ' +char1
|
139 |
lines.append(line)
|
140 |
line = ''
|
141 |
i += 1
|
142 |
elif char1 == ',':
|
143 |
-
outPutJson = outPutJson +'\n'
|
144 |
|
145 |
-
line += '\n'+spaceCount*2*' '
|
146 |
lines.append(line)
|
147 |
-
line=''
|
148 |
else:
|
149 |
-
outPutJson=outPutJson+char1
|
150 |
|
151 |
line += char1
|
152 |
print(len(lines))
|
153 |
print(''.join(lines))
|
154 |
-
return ''.join(lines)
|
|
|
|
|
155 |
def main():
|
156 |
print('欢迎来到ITP监控平台系统')
|
157 |
while True:
|
158 |
try:
|
159 |
-
Request=input('请输入从Charles中抓包的URLs:')
|
160 |
Request = 'curl -H "Host: pre-release.gravity.place" -H "User-Agent: okhttp/3.12.13" --compressed "http://pre-release.gravity.place/gravity/metaverse/starUserList?country=CN&product=gravity&star_id=23&sys_lang=ja&uwd=YRHBwL8DHv04H3JUkjFuiWFQgdmQxIy64bp7qHpU4JbPo1wW6IcEaMMp6LsT34op%0A&app_version=7.7.0&user_country=CN&sign=31caf01c033f194abc5287df89ff80bb&source=star_detail&pkg=anonymous.sns.community.gravity&token=1QZVaDtlJ21T9CYEPRAKqC1X14y6xD5%252Bfetlx%252FTJE%252Bnl2lganNSgB9BSTNgdUCCN&languageV2=ja&referrer=Organic&zone=8&system_version=10&sdk_version=29&model=V2023A&device=android&brand=vivo&ts=1686842126"'
|
161 |
-
url=ReRequestUrl(Request)
|
162 |
-
html=getHtml(url)
|
163 |
-
jsonOuputPath='outputJson.json'
|
164 |
-
jsondata=excuJson(html,jsonOuputPath)
|
165 |
-
NewJsonStr=showJson(jsondata)
|
166 |
-
|
167 |
except Exception as e:
|
168 |
print(e)
|
169 |
|
|
|
170 |
def GradioMain():
|
171 |
-
textbook=gr.Text(lines=2,placeholder='Requests Url')
|
172 |
-
grd=gr.Interface(fn=getITP,inputs=textbook,outputs=['text','text'], title="ITP proudct Interface system ",
|
|
|
|
|
173 |
grd.launch()
|
|
|
|
|
174 |
if "__main__" == __name__:
|
175 |
-
|
176 |
GradioMain()
|
|
|
3 |
import json
|
4 |
|
5 |
import gradio as gr
|
6 |
+
|
7 |
+
|
8 |
def ReRequestUrl(url):
|
9 |
try:
|
10 |
if 'gravity' not in url:
|
11 |
return ''
|
12 |
+
Newurl = 'http://' + re.findall('http://(.*?)"', url)[0]
|
13 |
|
14 |
+
signed = re.findall('sign=(.*?)&', Newurl)[0]
|
15 |
|
16 |
+
FinnalUrl = Newurl.replace(signed, 'fsdfgasdgf34578348jiren')
|
17 |
|
18 |
req = requests.get(FinnalUrl)
|
19 |
|
|
|
22 |
except:
|
23 |
return ''
|
24 |
|
25 |
+
|
26 |
def GetList(data):
|
27 |
+
if len(data) == 0:
|
28 |
+
newJson = {}
|
29 |
+
newJson['type'] = 'string'
|
30 |
return newJson
|
31 |
else:
|
32 |
+
data = data[0]
|
33 |
+
if type(data) == dict:
|
34 |
+
newItemjson = GetJson(data)
|
35 |
|
36 |
return newItemjson
|
37 |
|
38 |
|
39 |
def GetJson(data):
|
40 |
+
newJson = {}
|
41 |
+
newJson['type'] = 'object'
|
42 |
+
newJson['required'] = []
|
43 |
+
propertiesJson = {}
|
44 |
+
for key, value in data.items():
|
45 |
+
|
46 |
+
if type(value) == str:
|
47 |
+
propertiesJson[key] = {'type': 'string'}
|
48 |
+
elif type(value) == int:
|
49 |
propertiesJson[key] = {'type': 'number'}
|
50 |
elif type(value) == list:
|
51 |
+
newListJson = {}
|
52 |
+
newListJson['type'] = 'array'
|
53 |
newListJson['items'] = GetList(value)
|
54 |
+
propertiesJson[key] = newListJson
|
55 |
elif type(value) == dict:
|
56 |
+
newListJson = GetJson(value)
|
57 |
propertiesJson[key] = newListJson
|
58 |
else:
|
59 |
+
print(value, type(value))
|
60 |
propertiesJson[key] = None
|
61 |
|
62 |
+
newJson['properties'] = propertiesJson
|
63 |
return newJson
|
64 |
+
|
65 |
+
|
66 |
def gerTtr(typeStr):
|
67 |
+
str = str(typeStr)
|
68 |
+
NewStr = re.findall('<class \'(.*?)\'>', str)
|
69 |
return NewStr
|
70 |
|
|
|
71 |
|
72 |
+
def excuJson(html, jsonOuputPath):
|
73 |
+
# jsonOuputPath='jsonOutput.json'
|
74 |
|
75 |
+
data = json.loads(html)
|
76 |
+
# print(data)
|
77 |
+
# newJson==GetJson(data)
|
78 |
|
79 |
+
listL = []
|
80 |
+
dictL = {}
|
81 |
+
jsonOutput = GetJson(data)
|
82 |
print(jsonOutput)
|
83 |
+
json.dump(jsonOutput, open(jsonOuputPath, 'w', encoding='utf-8'), indent=2, ensure_ascii=False)
|
84 |
|
85 |
+
# print(gerTtr(type('uk123')))
|
86 |
+
print(type('uk123') == str)
|
87 |
print(type(listL))
|
88 |
print(type(1))
|
89 |
print(type(dictL))
|
90 |
return jsonOutput
|
91 |
|
92 |
+
|
93 |
def getHtml(url):
|
94 |
try:
|
95 |
+
headers = {
|
96 |
+
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'}
|
97 |
+
res = requests.get(url, headers=headers)
|
98 |
+
if res.status_code == 200:
|
99 |
return res.text
|
100 |
else:
|
101 |
+
print('Error Code:' + str(res.status_code))
|
102 |
return ''
|
103 |
except Exception as e:
|
104 |
print(e)
|
105 |
+
|
106 |
+
|
107 |
def getITP(Request):
|
108 |
+
# Request = 'curl -H "Host: pre-release.gravity.place" -H "User-Agent: okhttp/3.12.13" --compressed "http://pre-release.gravity.place/gravity/metaverse/starUserList?country=CN&product=gravity&star_id=23&sys_lang=ja&uwd=YRHBwL8DHv04H3JUkjFuiWFQgdmQxIy64bp7qHpU4JbPo1wW6IcEaMMp6LsT34op%0A&app_version=7.7.0&user_country=CN&sign=31caf01c033f194abc5287df89ff80bb&source=star_detail&pkg=anonymous.sns.community.gravity&token=1QZVaDtlJ21T9CYEPRAKqC1X14y6xD5%252Bfetlx%252FTJE%252Bnl2lganNSgB9BSTNgdUCCN&languageV2=ja&referrer=Organic&zone=8&system_version=10&sdk_version=29&model=V2023A&device=android&brand=vivo&ts=1686842126"'
|
109 |
url = ReRequestUrl(Request)
|
110 |
html = getHtml(url)
|
111 |
jsonOuputPath = 'outputJson.json'
|
112 |
+
jsonOutput = excuJson(html, jsonOuputPath)
|
113 |
print(jsonOutput)
|
114 |
|
115 |
+
return url, showJson(jsonOutput)
|
116 |
+
|
117 |
|
118 |
def showJson(jsondata):
|
119 |
+
jsonStr = str(jsondata).replace(' ', '').replace('\n', '')
|
120 |
+
outPutJson = ''
|
121 |
+
spaceCount = 0
|
122 |
+
lines = []
|
123 |
+
line = ''
|
124 |
for i in range(len(jsonStr)):
|
125 |
+
char1 = jsonStr[i]
|
126 |
|
127 |
+
if char1 == '{':
|
128 |
+
spaceCount += 1
|
129 |
+
outPutJson = outPutJson + char1 + '\n'
|
130 |
|
131 |
+
line += char1 + '\n' + spaceCount * 2 * ' '
|
|
|
|
|
|
|
|
|
132 |
lines.append(line)
|
133 |
+
line = ''
|
134 |
+
elif char1 == '}' and i != len(jsonStr) - 1 and jsonStr[i + 1] != ',':
|
135 |
spaceCount -= 1
|
136 |
+
outPutJson = outPutJson + '\n' + spaceCount * 2 * ' ' + char1
|
137 |
|
138 |
+
line += '\n' + spaceCount * 2 * ' ' + char1
|
139 |
lines.append(line)
|
140 |
line = ''
|
141 |
+
elif char1 == '}' and i != len(jsonStr) - 1 and jsonStr[i + 1] == ',':
|
142 |
spaceCount -= 1
|
143 |
+
outPutJson = outPutJson + '\n' + jsonStr[i + 1]
|
|
|
144 |
|
145 |
+
line += '\n' + spaceCount * 2 * ' ' + char1
|
146 |
lines.append(line)
|
147 |
line = ''
|
148 |
i += 1
|
149 |
elif char1 == ',':
|
150 |
+
outPutJson = outPutJson + char1+'\n'
|
151 |
|
152 |
+
line += char1+'\n' + spaceCount * 2 * ' '
|
153 |
lines.append(line)
|
154 |
+
line = ''
|
155 |
else:
|
156 |
+
outPutJson = outPutJson + char1
|
157 |
|
158 |
line += char1
|
159 |
print(len(lines))
|
160 |
print(''.join(lines))
|
161 |
+
return ''.join(lines).replace('\'','\"').replace('None','null')+'\n'+'}'
|
162 |
+
|
163 |
+
|
164 |
def main():
|
165 |
print('欢迎来到ITP监控平台系统')
|
166 |
while True:
|
167 |
try:
|
168 |
+
Request = input('请输入从Charles中抓包的URLs:')
|
169 |
Request = 'curl -H "Host: pre-release.gravity.place" -H "User-Agent: okhttp/3.12.13" --compressed "http://pre-release.gravity.place/gravity/metaverse/starUserList?country=CN&product=gravity&star_id=23&sys_lang=ja&uwd=YRHBwL8DHv04H3JUkjFuiWFQgdmQxIy64bp7qHpU4JbPo1wW6IcEaMMp6LsT34op%0A&app_version=7.7.0&user_country=CN&sign=31caf01c033f194abc5287df89ff80bb&source=star_detail&pkg=anonymous.sns.community.gravity&token=1QZVaDtlJ21T9CYEPRAKqC1X14y6xD5%252Bfetlx%252FTJE%252Bnl2lganNSgB9BSTNgdUCCN&languageV2=ja&referrer=Organic&zone=8&system_version=10&sdk_version=29&model=V2023A&device=android&brand=vivo&ts=1686842126"'
|
170 |
+
url = ReRequestUrl(Request)
|
171 |
+
html = getHtml(url)
|
172 |
+
jsonOuputPath = 'outputJson.json'
|
173 |
+
jsondata = excuJson(html, jsonOuputPath)
|
174 |
+
NewJsonStr = showJson(jsondata)
|
175 |
+
# print(NewJsonStr)
|
176 |
except Exception as e:
|
177 |
print(e)
|
178 |
|
179 |
+
|
180 |
def GradioMain():
|
181 |
+
textbook = gr.Text(lines=2, placeholder='Requests Url')
|
182 |
+
grd = gr.Interface(fn=getITP, inputs=textbook, outputs=['text', 'text'], title="ITP proudct Interface system ",
|
183 |
+
description="将文件用charles 抓包得到的requests转化成 可以直接用的Url 和json", examples=[[
|
184 |
+
'curl -H "Host: pre-release.gravity.place" -H "User-Agent: okhttp/3.12.13" --compressed "http://pre-release.gravity.place/gravity/metaverse/starUserList?country=CN&product=gravity&star_id=23&sys_lang=ja&uwd=YRHBwL8DHv04H3JUkjFuiWFQgdmQxIy64bp7qHpU4JbPo1wW6IcEaMMp6LsT34op%0A&app_version=7.7.0&user_country=CN&sign=31caf01c033f194abc5287df89ff80bb&source=star_detail&pkg=anonymous.sns.community.gravity&token=1QZVaDtlJ21T9CYEPRAKqC1X14y6xD5%252Bfetlx%252FTJE%252Bnl2lganNSgB9BSTNgdUCCN&languageV2=ja&referrer=Organic&zone=8&system_version=10&sdk_version=29&model=V2023A&device=android&brand=vivo&ts=1686842126"']])
|
185 |
grd.launch()
|
186 |
+
|
187 |
+
|
188 |
if "__main__" == __name__:
|
189 |
+
# main()
|
190 |
GradioMain()
|