mirror of
https://github.com/RGBCube/GitHubWrapper
synced 2025-05-16 22:15:09 +00:00
Small tweaks to setattr behaviour
This commit is contained in:
parent
1316f11dd2
commit
eb7e07f74d
1 changed files with 11 additions and 11 deletions
|
@ -1,6 +1,5 @@
|
||||||
#== objects.py ==#
|
#== objects.py ==#
|
||||||
|
|
||||||
from collections import namedtuple
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
@ -35,7 +34,7 @@ class APIOBJECT:
|
||||||
|
|
||||||
class _BaseUser(APIOBJECT):
|
class _BaseUser(APIOBJECT):
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
'name',
|
'login',
|
||||||
'id',
|
'id',
|
||||||
)
|
)
|
||||||
def __init__(self, response: dict, session: aiohttp.ClientSession) -> None:
|
def __init__(self, response: dict, session: aiohttp.ClientSession) -> None:
|
||||||
|
@ -55,21 +54,22 @@ class User(_BaseUser):
|
||||||
'public_repos',
|
'public_repos',
|
||||||
'public_gists',
|
'public_gists',
|
||||||
'followers',
|
'followers',
|
||||||
'following'
|
'following',
|
||||||
'created_at',
|
'created_at',
|
||||||
)
|
)
|
||||||
def __init__(self, response: dict, session: aiohttp.ClientSession) -> None:
|
def __init__(self, response: dict, session: aiohttp.ClientSession) -> None:
|
||||||
super().__init__(response, session)
|
super().__init__(response, session)
|
||||||
tmp = self.__slots__
|
tmp = self.__slots__ + _BaseUser.__slots__
|
||||||
keys = {key: value for key,value in self.response.items() if key in tmp}
|
keys = {key: value for key,value in self._response.items() if key in tmp}
|
||||||
for key, value in keys.items():
|
for key, value in keys.items():
|
||||||
if key == 'login':
|
|
||||||
self.login = value
|
|
||||||
return
|
|
||||||
|
|
||||||
if '_at' in key and value is not None:
|
if '_at' in key and value is not None:
|
||||||
setattr(self, key, dt_formatter(value))
|
setattr(self, key, dt_formatter(value))
|
||||||
return
|
continue
|
||||||
|
else:
|
||||||
|
setattr(self, key, value)
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
|
||||||
|
@ -80,4 +80,4 @@ class User(_BaseUser):
|
||||||
async def get_user(cls, session: aiohttp.ClientSession, username: str) -> 'User':
|
async def get_user(cls, session: aiohttp.ClientSession, username: str) -> 'User':
|
||||||
"""Returns a User object from the username, with the mentions slots."""
|
"""Returns a User object from the username, with the mentions slots."""
|
||||||
response = await http.get_user(session, username)
|
response = await http.get_user(session, username)
|
||||||
return User(response, session)
|
return User(response, session)
|
Loading…
Add table
Add a link
Reference in a new issue