Spaces:
Sleeping
Sleeping
File size: 7,413 Bytes
d456d30 fc87e49 d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af f7f3ea3 d456d30 f7f3ea3 d456d30 7db66af f7f3ea3 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 7db66af f7f3ea3 7db66af f7f3ea3 7db66af f7f3ea3 7db66af f7f3ea3 d456d30 7db66af d456d30 7db66af d456d30 7db66af d456d30 ea580c6 |
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 |
import requests
import re
import json
import gradio as gr
def ReRequestUrl(url):
try:
if 'gravity' not in url:
return ''
Newurl = 'http://' + re.findall('http://(.*?)"', url)[0]
signed = re.findall('sign=(.*?)&', Newurl)[0]
FinnalUrl = Newurl.replace(signed, 'fsdfgasdgf34578348jiren')
req = requests.get(FinnalUrl)
if req.status_code == 200:
return req.url
except:
return ''
def GetList(data):
if len(data) == 0:
newJson = {}
newJson['type'] = 'string'
return newJson
else:
data = data[0]
if type(data) == dict:
newItemjson = GetJson(data)
elif type(data) == list:
newItemjson = GetList(data)
elif type(data) == str:
newItemjson = {}
newItemjson['type'] = 'string'
else:
newItemjson = {}
newItemjson['type'] = 'string'
return newItemjson
return ''
def GetJson(data):
newJson = {}
newJson['type'] = 'object'
newJson['required'] = []
propertiesJson = {}
for key, value in data.items():
print(key,value)
if type(value) == str:
propertiesJson[key] = {'type': 'string'}
elif type(value) == int:
propertiesJson[key] = {'type': 'number'}
elif type(value) == list:
newListJson = {}
newListJson['type'] = 'array'
newListJson['items'] = GetList(value)
propertiesJson[key] = newListJson
elif type(value) == dict:
newListJson = GetJson(value)
propertiesJson[key] = newListJson
else:
print(value, type(value))
propertiesJson[key] = None
newJson['properties'] = propertiesJson
return newJson
def gerTtr(typeStr):
str = str(typeStr)
NewStr = re.findall('<class \'(.*?)\'>', str)
return NewStr
def excuJson(html, jsonOuputPath):
# jsonOuputPath='jsonOutput.json'
data = json.loads(html)
# print(data)
# newJson==GetJson(data)
listL = []
dictL = {}
jsonOutput = GetJson(data)
print(jsonOutput)
json.dump(jsonOutput, open(jsonOuputPath, 'w', encoding='utf-8'), indent=2, ensure_ascii=False)
# print(gerTtr(type('uk123')))
print(type('uk123') == str)
print(type(listL))
print(type(1))
print(type(dictL))
return jsonOutput
def getHtml(url):
try:
headers = {
'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'}
res = requests.get(url, headers=headers)
if res.status_code == 200:
return res.text
else:
print('Error Code:' + str(res.status_code))
return ''
except Exception as e:
print(e)
def getITP(Request):
# 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"'
url = ReRequestUrl(Request)
html = getHtml(url)
jsonOuputPath = 'outputJson.json'
jsonOutput = excuJson(html, jsonOuputPath)
print(jsonOutput)
return url, showJson(jsonOutput)
def showJson(jsondata):
jsonStr = str(jsondata).replace(' ', '').replace('\n', '')
outPutJson = ''
spaceCount = 0
lines = []
line = ''
for i in range(len(jsonStr)):
char1 = jsonStr[i]
if char1 == '{':
spaceCount += 1
outPutJson = outPutJson + char1 + '\n'
line += char1 + '\n' + spaceCount * 2 * ' '
lines.append(line)
line = ''
elif char1 == '}' and i != len(jsonStr) - 1 and jsonStr[i + 1] != ',':
spaceCount -= 1
outPutJson = outPutJson + '\n' + spaceCount * 2 * ' ' + char1
line += '\n' + spaceCount * 2 * ' ' + char1
lines.append(line)
line = ''
elif char1 == '}' and i != len(jsonStr) - 1 and jsonStr[i + 1] == ',':
spaceCount -= 1
outPutJson = outPutJson + '\n' + jsonStr[i + 1]
line += '\n' + spaceCount * 2 * ' ' + char1
lines.append(line)
line = ''
i += 1
elif char1 == ',':
outPutJson = outPutJson + char1+'\n'
line += char1+'\n' + spaceCount * 2 * ' '
lines.append(line)
line = ''
else:
outPutJson = outPutJson + char1
line += char1
print(len(lines))
print(''.join(lines))
return ''.join(lines).replace('\'','\"').replace('None','null')+'\n'+'}'
def main():
print('欢迎来到ITP监控平台系统')
while True:
try:
Request = input('请输入从Charles中抓包的URLs:')
# 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"'
url = ReRequestUrl(Request)
print(url)
html = getHtml(url)
jsonOuputPath = 'outputJson.json'
jsondata = excuJson(html, jsonOuputPath)
print(jsondata)
NewJsonStr = showJson(jsondata)
print(NewJsonStr)
except Exception as e:
print(e)
def GradioMain():
textbook = gr.Text(lines=2, placeholder='Requests Url')
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"']])
grd.launch()
if "__main__" == __name__:
#main()
GradioMain()
|