import requests from requests import Response, Request, Session from src.profiles import Profiles from src.accounts import Accounts from src import urls class Client: def __init__(self, url: str): self.url: str = url self.token: str = None self.session: Session = Session() self.accounts: Accounts = Accounts(self) self.profiles: Profiles = Profiles(self) def is_authentificate(self): return (not self.token is None) def login(self, username: str, password: str): response: Response = self._post(urls.accounts_login, {'username': username, 'password': password}) return response.content def _post(self, uri: str, data: dict = {}): url: str = self.url + uri if self.token is None: response: Response = self.session.get(url) self.token = response.cookies.get('csrftoken') data.update({'csrfmiddlewaretoken': self.token}) response: Response = self.session.post(url, data = data, headers = dict(Referer=url)) self.token = response.cookies.get('csrftoken') return response def _get(self, uri: str): url: str = self.url + uri response: Response = self.session.get(url) self.token = response.cookies.get('csrftoken') return response