init commit
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
test.py
|
||||||
|
venv/
|
||||||
|
__pycache__/
|
||||||
1
itd/__init__.py
Normal file
1
itd/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from itd.client import Client as ITDClient
|
||||||
11
itd/client.py
Normal file
11
itd/client.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
from itd.users import get_user
|
||||||
|
|
||||||
|
class Client:
|
||||||
|
def __init__(self, token: str):
|
||||||
|
self.token = token.replace('Bearer ', '')
|
||||||
|
|
||||||
|
def get_user(self, username: str) -> dict:
|
||||||
|
return get_user(self.token, username)
|
||||||
|
|
||||||
|
def get_me(self) -> dict:
|
||||||
|
return self.get_user('me')
|
||||||
24
itd/request.py
Normal file
24
itd/request.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
from requests import Session
|
||||||
|
|
||||||
|
s = Session()
|
||||||
|
|
||||||
|
|
||||||
|
def fetch(token: str, method: str, url: str):
|
||||||
|
res = eval(f's.{method}')(f'https://итд.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",
|
||||||
|
"Authorization": 'Bearer ' + token,
|
||||||
|
"Sec-GPC": "1",
|
||||||
|
"Upgrade-Insecure-Requests": "1",
|
||||||
|
"Sec-Fetch-Dest": "document",
|
||||||
|
"Sec-Fetch-Mode": "navigate",
|
||||||
|
"Sec-Fetch-Site": "none",
|
||||||
|
"Sec-Fetch-User": "?1",
|
||||||
|
"Priority": "u=0, i",
|
||||||
|
"Pragma": "no-cache",
|
||||||
|
"Cache-Control": "no-cache",
|
||||||
|
"TE": "trailers"
|
||||||
|
})
|
||||||
|
res.raise_for_status()
|
||||||
|
return res.json()
|
||||||
5
itd/users.py
Normal file
5
itd/users.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
from itd.request import fetch
|
||||||
|
|
||||||
|
|
||||||
|
def get_user(token: str, username: str):
|
||||||
|
return fetch(token, 'get', f'users/{username}')
|
||||||
0
requirements.txt
Normal file
0
requirements.txt
Normal file
Reference in New Issue
Block a user