-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
major update: api and recommendations
- Loading branch information
Showing
5 changed files
with
89 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
from .search import ( | ||
Octokit, | ||
main | ||
) | ||
from .user_data import get_repos | ||
from .api import ( | ||
User, | ||
) | ||
from .octokit import Octokit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import asyncio | ||
from datetime import datetime | ||
from typing import Optional, List | ||
|
||
|
||
class Octokit: | ||
def __init__(self, auth: str, session): | ||
self.auth = auth | ||
self.session = session | ||
|
||
async def request(self, | ||
method: str, | ||
url: str, | ||
params: Optional[dict]=None): | ||
headers = { | ||
'Authorization': 'BEARER ' + self.auth, | ||
'Accept': 'application/vnd.github+json', | ||
} | ||
|
||
url = 'https://api.github.com' + url | ||
|
||
while True: | ||
async with self.session.request(method, url, headers=headers, params=params) as response: | ||
if response.status == 403: | ||
reset_time = datetime.fromtimestamp(int(response.headers["X-RateLimit-Reset"])) | ||
sleep_time = (reset_time - datetime.now()).total_seconds() + 5 | ||
await asyncio.sleep(sleep_time) | ||
else: | ||
response.raise_for_status() | ||
return await response.json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters