mirror of
https://github.com/RGBCube/GitHubWrapper
synced 2025-05-18 15:05:08 +00:00
Added bits for an Auth to increase ratelimits
This commit is contained in:
parent
d32ec86671
commit
01050b4700
1 changed files with 6 additions and 5 deletions
|
@ -27,12 +27,13 @@ trace_config = aiohttp.TraceConfig()
|
|||
trace_config.on_request_start.append(on_req_start)
|
||||
trace_config.on_request_end.append(on_req_end)
|
||||
|
||||
async def make_session(*, headers: dict[str, str]) -> aiohttp.ClientSession:
|
||||
async def make_session(*, headers: dict[str, str], authorization: aiohttp.BasicAuth | None) -> aiohttp.ClientSession:
|
||||
"""This makes the ClientSession, attaching the trace config and ensuring a UA header is present."""
|
||||
if not headers.get('User-Agent'):
|
||||
headers['User-Agent'] = 'Github-API-Wrapper'
|
||||
|
||||
session = aiohttp.ClientSession(
|
||||
auth=authorization,
|
||||
headers=headers,
|
||||
trace_configs=[trace_config]
|
||||
)
|
||||
|
@ -41,10 +42,10 @@ async def make_session(*, headers: dict[str, str]) -> aiohttp.ClientSession:
|
|||
# user-related functions / utils
|
||||
GitHubUserData = dict[str, str | int]
|
||||
|
||||
async def get_user(session: aiohttp.ClientSession, *, _username: str) -> GitHubUserData:
|
||||
async def get_user(session: aiohttp.ClientSession, username: str) -> GitHubUserData:
|
||||
"""Returns a user's public data in JSON format."""
|
||||
result = await session.get(USERS_URL.format(_username))
|
||||
result = await session.get(USERS_URL.format(username))
|
||||
if result.status == 200:
|
||||
return await result.json()
|
||||
raise UserNotFound()
|
||||
raise UserNotFound
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue