import requests import re import json from fake_useragent import UserAgent 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) return newItemjson def GetJson(data): newJson={} newJson['type']='object' newJson['required']=[] propertiesJson={} for key,value in data.items(): 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('',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':UserAgent().random} 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 +jsonStr[i+1] lines.append(line) line = '' i += 1 elif char1 == ',': outPutJson = outPutJson +'\n' line += '\n'+spaceCount*2*' ' lines.append(line) line='' else: outPutJson=outPutJson+char1 line += char1 print(len(lines)) print(''.join(lines)) return ''.join(lines) 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) html=getHtml(url) jsonOuputPath='outputJson.json' jsondata=excuJson(html,jsonOuputPath) 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()