├── README.md └── htconv.py /README.md: -------------------------------------------------------------------------------- 1 | # HTTP TOOLKIT CONVENTER 2 | 3 | Convert http toolkit string to python httpx request 4 | 5 | ![Logo](https://media.discordapp.net/attachments/1006892478361784390/1039992321342709861/fdgdgdfgdf.png?width=1438&height=671) 6 | ## Usage 7 | 8 | 9 | 10 | ```python 11 | import htconv 12 | 13 | stringx = """METHOD: POST 14 | URL 15 | https://graphigo.prd.dlive.tv/ 16 | HEADERS 17 | accept: 18 | application/json 19 | accept-encoding: 20 | gzip 21 | connection: 22 | Keep-Alive 23 | content-length: 24 | 418 25 | content-type: 26 | application/json; charset=utf-8 27 | host: 28 | graphigo.prd.dlive.tv 29 | user-agent: 30 | okhttp/4.9.2 31 | x-apollo-cache-do-not-store: 32 | false 33 | x-apollo-cache-fetch-strategy: 34 | NETWORK_ONLY 35 | x-apollo-cache-key: 36 | c246592c6b4efd023acdeba5e1dd3032 37 | x-apollo-expire-after-read: 38 | false 39 | x-apollo-expire-timeout: 40 | 0 41 | x-apollo-operation-id: 42 | cb0be2578fe8f5192e35c3ff4069e8b6c8b0f117b788dc43f63a1465a2948a5c 43 | x-apollo-operation-name: 44 | IsBlockedRegion 45 | x-apollo-prefetch: 46 | false 47 | x-dlive-mid: 48 | 00000000-2ac5-add0-ffff-ffffef05ac4a 49 | x-dlive-mtype: 50 | android 51 | x-dlive-mversion: 52 | 1.16.44""" 53 | 54 | res = htconv.ColventerHttp().convert(stringx, oneline=None) 55 | 56 | print(res) 57 | ``` 58 | ``` 59 | headers = { 60 | "accept:": "application/json", 61 | "accept-encoding:": "gzip", 62 | "connection:": "Keep-Alive", 63 | "content-length:": "418", 64 | "content-type:": "application/json; charset=utf-8", 65 | "host:": "graphigo.prd.dlive.tv", 66 | "user-agent:": "okhttp/4.9.2", 67 | "x-apollo-cache-do-not-store:": "false", 68 | "x-apollo-cache-fetch-strategy:": "NETWORK_ONLY", 69 | "x-apollo-cache-key:": "c246592c6b4efd023acdeba5e1dd3032", 70 | "x-apollo-expire-after-read:": "false", 71 | "x-apollo-expire-timeout:": "0", 72 | "x-apollo-operation-id:": "cb0be2578fe8f5192e35c3ff4069e8b6c8b0f117b788dc43f63a1465a2948a5c", 73 | "x-apollo-operation-name:": "IsBlockedRegion", 74 | "x-apollo-prefetch:": "false", 75 | "x-dlive-mid:": "00000000-2ac5-add0-ffff-ffffef05ac4a", 76 | "x-dlive-mtype:": "android", 77 | "x-dlive-mversion:": "1.16.44" 78 | } 79 | httpx.post('https://graphigo.prd.dlive.tv/',headers=headers) 80 | -------------------------------------------------------------------------------- /htconv.py: -------------------------------------------------------------------------------- 1 | import numpy, json, httpx 2 | 3 | class ColventerHttp: 4 | def __init__(self) -> None: 5 | self.oneline = None 6 | self.request_string = None 7 | self.request_string_converted = None 8 | self.methods_string = {"POST":"post","GET":"get"} 9 | 10 | # REQUEST 11 | self.method = None 12 | self.url = None 13 | self.headers = {} 14 | 15 | def convert(self,code,oneline=None): 16 | self.oneline = oneline 17 | self.request_string = code 18 | return self.start() 19 | 20 | def start(self): 21 | self.method = self.methods_string[self.request_string.split("METHOD: ")[1].split("\n")[0]] 22 | self.url = self.request_string.split("URL\n")[1].split("\n")[0] 23 | if "HEADERS\n" in self.request_string: 24 | 25 | lines = self.request_string.split("HEADERS\n")[1].splitlines() 26 | pairs = zip(lines[0::2], lines[1::2]) 27 | for i in list(pairs): 28 | self.headers[numpy.asarray(i)[0][:-1]] = numpy.asarray(i)[1] 29 | else: 30 | self.headers = None 31 | 32 | if self.oneline == True: 33 | x = f"headers = {str(self.headers)}" 34 | elif self.oneline == None: 35 | x = f"headers = {json.dumps(self.headers, indent=4)}" 36 | 37 | return x + f"""\nhttpx.{self.method}('{self.url}',headers=headers)""" 38 | 39 | --------------------------------------------------------------------------------