diff --git a/README.md b/README.md index 919f42a..ac6e22f 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ fetch(c.token, 'метод', 'эндпоинт', {'данные': 'данные' Из методов поддерживается `get`, `post`, `put` итд, которые есть в `requests` К названию эндпоинта добавляется домен итд и `api`, то есть в этом примере отпарвится `https://xn--d1ah4a.com/api/эндпоинт`. -> ![INFO] +> [!INFO] > `xn--d1ah4a.com` - punycode от "итд.com" ## прочее @@ -47,4 +47,4 @@ fetch(c.token, 'метод', 'эндпоинт', {'данные': 'данные' Идея (и часть эндпоинтов): https://github.com/FriceKa/ITD-SDK-js - По сути этот проект является реворком, просто на другом языке -Автор: [SizedBox](https://xn--d1ah4a.com/SizedBox) (в итд) [@desicars](https://t.me/desicars) (в тг) \ No newline at end of file +Автор: [itd_sdk](https://xn--d1ah4a.com/itd_sdk) (в итд) [@desicars](https://t.me/desicars) (в тг) \ No newline at end of file diff --git a/itd/request.py b/itd/request.py index 9e5fa08..0bb463a 100644 --- a/itd/request.py +++ b/itd/request.py @@ -3,8 +3,9 @@ from requests import Session s = Session() -def fetch(token: str, method: str, url: str, params: dict = {}): - res = eval(f's.{method}')(f'https://xn--d1ah4a.com/api/{url}', timeout=20, params=params, headers={ +def fetch(token: str, method: str, url: str, params: dict = {}, files: list = []): + base = f'https://xn--d1ah4a.com/api/{url}' + headers = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language": "ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3", "Accept-Encoding": "gzip, deflate, br, zstd", @@ -19,7 +20,13 @@ def fetch(token: str, method: str, url: str, params: dict = {}): "Pragma": "no-cache", "Cache-Control": "no-cache", "TE": "trailers" - }) + } + method = method.lower() + if method == "get": + res = s.get(base, timeout=20, params=params, headers=headers) + else: + res = s.request(method.upper(), base, timeout=20, json=params, headers=headers, files=files) + res.raise_for_status() return res.json() @@ -51,4 +58,4 @@ def refresh_auth(cookies: str): "TE": "trailers", }) res.raise_for_status() - return res.json()['accessToken'] \ No newline at end of file + return res.json()['accessToken']