From 1900a6f39058a1acf83fae1d3863992306c0ac64 Mon Sep 17 00:00:00 2001 From: starnakin Date: Sun, 5 Nov 2023 18:15:29 +0100 Subject: [PATCH] add: profiles class --- src/Client.py | 4 ++-- src/Profile.py | 33 +++++++++++++++++++++++---------- src/Profiles.py | 17 +++++++++++++++++ 3 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 src/Profiles.py diff --git a/src/Client.py b/src/Client.py index 21b4466..1d18023 100644 --- a/src/Client.py +++ b/src/Client.py @@ -1,7 +1,7 @@ import requests from requests import Response, Request, Session -import Profile +import Profiles import Accounts import urls @@ -12,7 +12,7 @@ class Client: self.token: str = None self.session: Session = Session() self.accounts: Account = Accounts.Account(self) - self.profile = Profile.Profile + self.profiles = Profiles.Profiles(self) def is_authentificate(self): return (not self.token is None) diff --git a/src/Profile.py b/src/Profile.py index 16d15d5..f6ef5ad 100644 --- a/src/Profile.py +++ b/src/Profile.py @@ -1,14 +1,27 @@ -import urls -import Client -from requests import Response class Profile: - def __init__(self, client, user_id: int): - response: Response = client._get(urls.profiles_page + str(user_id)) - if (response.content == b'Profile Not Found'): - return None - content: dict = eval(response.content) - self.username = content['username'] - self.password = content['password'] \ No newline at end of file + def __init__(self, data: dict = None, username: str = None, title: str = None): + + if (data is None): + self._from_value(username, title) + else: + self._from_dict(data) + + 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) diff --git a/src/Profiles.py b/src/Profiles.py new file mode 100644 index 0000000..e23caff --- /dev/null +++ b/src/Profiles.py @@ -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) \ No newline at end of file