add: profiles class
This commit is contained in:
@ -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']
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user