import requests from requets.Session import Session from requests import Response, Requests import urls class Client: def __init__(self, url: str): self.url: str = url self.token: str = None self.session: Session = Session() response: Response = s.get(self.url) self.csrf_token = response.cookies['csrftoken'] def is_authentificate(self: Client): return (not self.token is None) def login(self: Client, username: str, password: str): response: Response = self._post(urls.accounts_login_url, {'username': username, 'password': password}) return response.content def register(self: Client, username: str, password: str): response: Response = self._post(urls.accounts_login_url, {'username': username, 'password': password}) return response.content def _post(self: Client, uri: str, data: dict): url: str = self.url + uri data.update({'csrfmiddlewaretoken': self.csrf_token}) response: Response = s.post(url, data = data, headers = dict(Referer=url)) return response.content