come commited on
Commit
d456d30
·
1 Parent(s): c6f114d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +176 -0
app.py ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import re
3
+ import json
4
+ from fake_useragent import UserAgent
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
+
18
+ if req.status_code == 200:
19
+ return req.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
+ def gerTtr(typeStr):
62
+ str=str(typeStr)
63
+ NewStr=re.findall('<class \'(.*?)\'>',str)
64
+ return NewStr
65
+
66
+ def excuJson(html,jsonOuputPath):
67
+
68
+ #jsonOuputPath='jsonOutput.json'
69
+
70
+ data=json.loads(html)
71
+ #print(data)
72
+ #newJson==GetJson(data)
73
+
74
+ listL=[]
75
+ dictL={}
76
+ jsonOutput=GetJson(data)
77
+ print(jsonOutput)
78
+ json.dump(jsonOutput,open(jsonOuputPath,'w',encoding='utf-8') ,indent=2,ensure_ascii=False)
79
+
80
+
81
+ # print(gerTtr(type('uk123')))
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={'user-agent':UserAgent().random}
91
+ res=requests.get(url,headers=headers)
92
+ if res.status_code==200:
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
+ if char1 =='{':
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 +jsonStr[i+1]
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
+ # print(NewJsonStr)
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 ",description="将文件用charles 抓包得到的requests转化成 可以直接用的Url 和json",examples=[['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"']])
173
+ grd.launch()
174
+ if "__main__" == __name__:
175
+ # main()
176
+ GradioMain()