add: profiles class
This commit is contained in:
parent
dc8b64573e
commit
1900a6f390
@ -1,7 +1,7 @@
|
|||||||
import requests
|
import requests
|
||||||
from requests import Response, Request, Session
|
from requests import Response, Request, Session
|
||||||
|
|
||||||
import Profile
|
import Profiles
|
||||||
import Accounts
|
import Accounts
|
||||||
|
|
||||||
import urls
|
import urls
|
||||||
@ -12,7 +12,7 @@ class Client:
|
|||||||
self.token: str = None
|
self.token: str = None
|
||||||
self.session: Session = Session()
|
self.session: Session = Session()
|
||||||
self.accounts: Account = Accounts.Account(self)
|
self.accounts: Account = Accounts.Account(self)
|
||||||
self.profile = Profile.Profile
|
self.profiles = Profiles.Profiles(self)
|
||||||
|
|
||||||
def is_authentificate(self):
|
def is_authentificate(self):
|
||||||
return (not self.token is None)
|
return (not self.token is None)
|
||||||
|
@ -1,14 +1,27 @@
|
|||||||
import urls
|
|
||||||
import Client
|
|
||||||
|
|
||||||
from requests import Response
|
|
||||||
|
|
||||||
class Profile:
|
class Profile:
|
||||||
|
|
||||||
def __init__(self, client, user_id: int):
|
def __init__(self, data: dict = None, username: str = None, title: str = None):
|
||||||
response: Response = client._get(urls.profiles_page + str(user_id))
|
|
||||||
if (response.content == b'Profile Not Found'):
|
if (data is None):
|
||||||
return None
|
self._from_value(username, title)
|
||||||
content: dict = eval(response.content)
|
else:
|
||||||
self.username = content['username']
|
self._from_dict(data)
|
||||||
self.password = content['password']
|
|
||||||
|
def _from_value(self, username: str, title: str):
|
||||||
|
self.username = username
|
||||||
|
self.title = title
|
||||||
|
return self
|
||||||
|
|
||||||
|
def _from_dict(self, data: dict):
|
||||||
|
self._from_value(data.get('username'), data.get('title'))
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
if isinstance(other, Profile):
|
||||||
|
return self.username == other.username and self.title == other.title
|
||||||
|
return False
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
return not self.__eq__(other)
|
||||||
|
17
src/Profiles.py
Normal file
17
src/Profiles.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import urls
|
||||||
|
import Client
|
||||||
|
|
||||||
|
from requests import Response
|
||||||
|
import Profile
|
||||||
|
|
||||||
|
class Profiles:
|
||||||
|
|
||||||
|
def __init__(self, client):
|
||||||
|
self.client = client
|
||||||
|
|
||||||
|
def get(self, user_id: int):
|
||||||
|
response: Response = self.client._get(urls.profiles_page + str(user_id))
|
||||||
|
if response.status_code == 404:
|
||||||
|
return None
|
||||||
|
content: dict = eval(response.content)
|
||||||
|
return Profile.Profile(data = content)
|
Loading…
Reference in New Issue
Block a user