diff --git a/Github/exceptions.py b/Github/exceptions.py index cde39d2..20381cb 100644 --- a/Github/exceptions.py +++ b/Github/exceptions.py @@ -28,23 +28,23 @@ class Ratelimited(APIError): class WillExceedRatelimit(APIError): """Raised when the library predicts the call will exceed the ratelimit, will abort the call by default.""" def __init__(self, response, count): - msg = 'Performing this action will exceed the ratelimit, aborting.\n{} remaining available calls, calls to make: {}' + msg = 'Performing this action will exceed the ratelimit, aborting.\n{} remaining available calls, calls to make: {}.' msg = msg.format(response.header['X-RateLimit-Remaining'], count) super().__init__(msg) class UserNotFound(APIError): def __init__(self): - msg = 'User not found' + msg = 'User not found.' super().__init__(msg) class OrganizationNotFound(APIError): def __init__(self): - msg = 'Organization not found' + msg = 'Organization not found.' super().__init__(msg) class RepositoryNotFound(APIError): def __init__(self): - msg = 'Repository not found' + msg = 'Repository not found.' super().__init__(msg) class ObjectNotFound(APIError): @@ -55,7 +55,7 @@ class ObjectNotFound(APIError): class NoAuthProvided(APIError): """Raised when no proper authorization or invalid authorization is given to the client""" def __init__(self): - msg = 'Without authorization, this client doesn\'t have it\'s own repository' + msg = 'Without authorization, this client doesn\'t have it\'s own repository.' super().__init__(msg) class InvalidAuthCombination(APIError): diff --git a/Github/main.py b/Github/main.py index 4fb82eb..8b367cc 100644 --- a/Github/main.py +++ b/Github/main.py @@ -12,7 +12,7 @@ from .objects import User class Github: _auth = None - _state = aiohttp.ClientSession + session = aiohttp.ClientSession def __init__( self, *, @@ -28,8 +28,8 @@ class Github: async def start(self): """Main entry point to the wrapper, this creates the ClientSession.""" - self._state = await http.make_session(headers=self._headers, authorization=self._auth) + self.session = await http.make_session(headers=self._headers, authorization=self._auth) async def get_user(self, username: str): """Fetch a Github user from their username.""" - return User(await http.get_user(self._state, username), self._state) \ No newline at end of file + return User(await http.get_user(self.session, username), self.session) \ No newline at end of file diff --git a/Github/objects.py b/Github/objects.py index 5293970..f115659 100644 --- a/Github/objects.py +++ b/Github/objects.py @@ -11,15 +11,23 @@ __all__ = ( 'User', ) +def dt_formatter(time_str): + if time_str is not None: + return datetime.strptime(time_str, r"%Y-%m-%dT%H:%M:%SZ") + return None + +def repr_dt(time_str): + return time_str.strftime(r'%d-%m-%Y, %H:%M:%S') + class APIOBJECT: __slots__ = ( '_response', - '_state' + 'session' ) def __init__(self, response: dict[str, str | int], session: aiohttp.ClientSession) -> None: self._response = response - self._state = session + self.session = session def __repr__(self) -> str: @@ -52,7 +60,28 @@ class User(_BaseUser): ) def __init__(self, response: dict, session: aiohttp.ClientSession) -> None: super().__init__(response, session) - ... + tmp = self.__slots__ + keys = {key: value for key,value in self.response.items() if key in tmp} + for key, value in key.items(): + if key == 'login': + self.login = value + return + + if '_at' in key and value is not None: + setattr(self, key, dt_formatter(value)) + return + + setattr(self, key, value) + + def __repr__(self): + return f'' + + @classmethod + async def get_user(self, session: aiohttp.ClientSession, username: str) -> 'User': + """Returns a User object from the username, with the mentions slots.""" + response = await http.get_user(session, username) + return User(response, session) +