Spaces:
Sleeping
Sleeping
come
commited on
Commit
·
b173b75
1
Parent(s):
ea580c6
Update app.py
Browse files
app.py
CHANGED
@@ -41,7 +41,7 @@ def GetList(data):
|
|
41 |
newItemjson = {}
|
42 |
newItemjson['type'] = 'string'
|
43 |
return newItemjson
|
44 |
-
return ''
|
45 |
|
46 |
|
47 |
def GetJson(data):
|
@@ -50,7 +50,7 @@ def GetJson(data):
|
|
50 |
newJson['required'] = []
|
51 |
propertiesJson = {}
|
52 |
for key, value in data.items():
|
53 |
-
|
54 |
if type(value) == str:
|
55 |
propertiesJson[key] = {'type': 'string'}
|
56 |
elif type(value) == int:
|
@@ -64,8 +64,8 @@ def GetJson(data):
|
|
64 |
newListJson = GetJson(value)
|
65 |
propertiesJson[key] = newListJson
|
66 |
else:
|
67 |
-
|
68 |
-
propertiesJson[key] = None
|
69 |
|
70 |
newJson['properties'] = propertiesJson
|
71 |
return newJson
|
@@ -79,22 +79,21 @@ def gerTtr(typeStr):
|
|
79 |
|
80 |
def excuJson(html, jsonOuputPath):
|
81 |
# jsonOuputPath='jsonOutput.json'
|
82 |
-
|
83 |
-
|
|
|
|
|
84 |
# print(data)
|
85 |
# newJson==GetJson(data)
|
86 |
|
87 |
listL = []
|
88 |
dictL = {}
|
89 |
jsonOutput = GetJson(data)
|
90 |
-
|
91 |
json.dump(jsonOutput, open(jsonOuputPath, 'w', encoding='utf-8'), indent=2, ensure_ascii=False)
|
92 |
|
93 |
# print(gerTtr(type('uk123')))
|
94 |
-
|
95 |
-
print(type(listL))
|
96 |
-
print(type(1))
|
97 |
-
print(type(dictL))
|
98 |
return jsonOutput
|
99 |
|
100 |
|
@@ -114,11 +113,19 @@ def getHtml(url):
|
|
114 |
|
115 |
def getITP(Request):
|
116 |
# 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"'
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
return url, showJson(jsonOutput)
|
124 |
|
@@ -164,8 +171,8 @@ def showJson(jsondata):
|
|
164 |
outPutJson = outPutJson + char1
|
165 |
|
166 |
line += char1
|
167 |
-
print(len(lines))
|
168 |
-
print(''.join(lines))
|
169 |
return ''.join(lines).replace('\'','\"').replace('None','null')+'\n'+'}'
|
170 |
|
171 |
|
@@ -174,15 +181,24 @@ def main():
|
|
174 |
while True:
|
175 |
try:
|
176 |
Request = input('请输入从Charles中抓包的URLs:')
|
|
|
177 |
# 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"'
|
|
|
178 |
url = ReRequestUrl(Request)
|
179 |
print(url)
|
180 |
html = getHtml(url)
|
181 |
jsonOuputPath = 'outputJson.json'
|
|
|
|
|
|
|
|
|
182 |
jsondata = excuJson(html, jsonOuputPath)
|
183 |
-
|
184 |
NewJsonStr = showJson(jsondata)
|
|
|
|
|
185 |
print(NewJsonStr)
|
|
|
186 |
except Exception as e:
|
187 |
print(e)
|
188 |
|
@@ -190,11 +206,11 @@ def main():
|
|
190 |
def GradioMain():
|
191 |
textbook = gr.Text(lines=2, placeholder='Requests Url')
|
192 |
grd = gr.Interface(fn=getITP, inputs=textbook, outputs=['text', 'text'], title="ITP proudct Interface system ",
|
193 |
-
description="将文件用charles 抓包得到的requests转化成 可以直接用的Url 和json", examples=[[
|
194 |
'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"']])
|
195 |
grd.launch()
|
196 |
|
197 |
|
198 |
if "__main__" == __name__:
|
199 |
-
|
200 |
GradioMain()
|
|
|
41 |
newItemjson = {}
|
42 |
newItemjson['type'] = 'string'
|
43 |
return newItemjson
|
44 |
+
return 'error'
|
45 |
|
46 |
|
47 |
def GetJson(data):
|
|
|
50 |
newJson['required'] = []
|
51 |
propertiesJson = {}
|
52 |
for key, value in data.items():
|
53 |
+
# print(key,value)
|
54 |
if type(value) == str:
|
55 |
propertiesJson[key] = {'type': 'string'}
|
56 |
elif type(value) == int:
|
|
|
64 |
newListJson = GetJson(value)
|
65 |
propertiesJson[key] = newListJson
|
66 |
else:
|
67 |
+
# print(value, type(value))
|
68 |
+
propertiesJson[key] = {"type":None}
|
69 |
|
70 |
newJson['properties'] = propertiesJson
|
71 |
return newJson
|
|
|
79 |
|
80 |
def excuJson(html, jsonOuputPath):
|
81 |
# jsonOuputPath='jsonOutput.json'
|
82 |
+
try:
|
83 |
+
data = json.loads(html)
|
84 |
+
except:
|
85 |
+
data = json.load(html)
|
86 |
# print(data)
|
87 |
# newJson==GetJson(data)
|
88 |
|
89 |
listL = []
|
90 |
dictL = {}
|
91 |
jsonOutput = GetJson(data)
|
92 |
+
# print(jsonOutput)
|
93 |
json.dump(jsonOutput, open(jsonOuputPath, 'w', encoding='utf-8'), indent=2, ensure_ascii=False)
|
94 |
|
95 |
# print(gerTtr(type('uk123')))
|
96 |
+
|
|
|
|
|
|
|
97 |
return jsonOutput
|
98 |
|
99 |
|
|
|
113 |
|
114 |
def getITP(Request):
|
115 |
# 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"'
|
116 |
+
try:
|
117 |
+
|
118 |
+
dataJson=json.loads(str(Request))
|
119 |
+
|
120 |
+
jsonOuputPath = 'outputJson.json'
|
121 |
+
jsonOutput = excuJson(dataJson, jsonOuputPath)
|
122 |
+
url=''
|
123 |
+
except:
|
124 |
+
url = ReRequestUrl(Request)
|
125 |
+
html = getHtml(url)
|
126 |
+
jsonOuputPath = 'outputJson.json'
|
127 |
+
jsonOutput = excuJson(html, jsonOuputPath)
|
128 |
+
|
129 |
|
130 |
return url, showJson(jsonOutput)
|
131 |
|
|
|
171 |
outPutJson = outPutJson + char1
|
172 |
|
173 |
line += char1
|
174 |
+
#print(len(lines))
|
175 |
+
#print(''.join(lines))
|
176 |
return ''.join(lines).replace('\'','\"').replace('None','null')+'\n'+'}'
|
177 |
|
178 |
|
|
|
181 |
while True:
|
182 |
try:
|
183 |
Request = input('请输入从Charles中抓包的URLs:')
|
184 |
+
|
185 |
# 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"'
|
186 |
+
|
187 |
url = ReRequestUrl(Request)
|
188 |
print(url)
|
189 |
html = getHtml(url)
|
190 |
jsonOuputPath = 'outputJson.json'
|
191 |
+
with open('jsonUrl.json', 'r') as outfile:
|
192 |
+
html=str(json.load(outfile))
|
193 |
+
print(html)
|
194 |
+
|
195 |
jsondata = excuJson(html, jsonOuputPath)
|
196 |
+
|
197 |
NewJsonStr = showJson(jsondata)
|
198 |
+
if NewJsonStr[0]==',':
|
199 |
+
NewJsonStr=NewJsonStr[1:]
|
200 |
print(NewJsonStr)
|
201 |
+
|
202 |
except Exception as e:
|
203 |
print(e)
|
204 |
|
|
|
206 |
def GradioMain():
|
207 |
textbook = gr.Text(lines=2, placeholder='Requests Url')
|
208 |
grd = gr.Interface(fn=getITP, inputs=textbook, outputs=['text', 'text'], title="ITP proudct Interface system ",
|
209 |
+
description="将文件用charles 抓包得到的requests/json 转化成 可以直接用的Url 和json", examples=[[
|
210 |
'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"']])
|
211 |
grd.launch()
|
212 |
|
213 |
|
214 |
if "__main__" == __name__:
|
215 |
+
# main()
|
216 |
GradioMain()
|