Compare commits

..

3 Commits

Author SHA1 Message Date
fb7c7e7bdf Use access token 2023-11-10 21:33:57 -05:00
0f323c6cfe Exclude configuration 2023-11-10 21:33:46 -05:00
ad857ab719 Add support for access token 2023-11-10 21:33:29 -05:00
3 changed files with 8 additions and 2 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@ venv/
__pycache__/ __pycache__/
*.py[cod] *.py[cod]
config.py

View File

@ -8,13 +8,15 @@ from requests.packages.urllib3.util.retry import Retry
class GitHubApi: class GitHubApi:
def __init__(self, headers=None, proxy=None): def __init__(self, token=None, headers=None, proxy=None):
self.base_url = 'https://api.github.com' self.base_url = 'https://api.github.com'
self.session = requests.Session() self.session = requests.Session()
retries = Retry(total=3, backoff_factor=1) retries = Retry(total=3, backoff_factor=1)
self.session.mount('https://', HTTPAdapter(max_retries=retries)) self.session.mount('https://', HTTPAdapter(max_retries=retries))
if token:
self.session.headers.update({'Authorization': f'Bearer {token}'})
if headers: if headers:
self.session.headers.update(headers) self.session.headers.update(headers)
if proxy: if proxy:

View File

@ -2,6 +2,8 @@
from loguru import logger from loguru import logger
from gitmon.api import GitHubApi from gitmon.api import GitHubApi
from config import token
def print_event(event): def print_event(event):
event_type = event.get('type') event_type = event.get('type')
@ -14,7 +16,7 @@ def print_event(event):
def main(): def main():
"""Main entry point.""" """Main entry point."""
api = GitHubApi() api = GitHubApi(token)
events = api.get_events() events = api.get_events()
for event in events: for event in events: