Compare commits

...

2 Commits

Author SHA1 Message Date
c29ad2f5be Monitor and log CreateEvents 2023-11-10 22:46:54 -05:00
5c4fb60ff2 Add countdown 2023-11-10 22:46:18 -05:00
2 changed files with 12 additions and 7 deletions

View File

@ -56,8 +56,7 @@ class GitHubApi:
"""Parse headers to update rate limits.""" """Parse headers to update rate limits."""
self.rate_reset = datetime.fromtimestamp(int(headers['x-ratelimit-reset'])) self.rate_reset = datetime.fromtimestamp(int(headers['x-ratelimit-reset']))
self.rate_remaining = int(headers['x-ratelimit-remaining']) self.rate_remaining = int(headers['x-ratelimit-remaining'])
logger.info(f'{self.rate_remaining} calls remaining until {self.rate_reset}') logger.info(f'{self.rate_remaining} calls remaining until {self.rate_reset} ({self.rate_reset - datetime.now()})')
def get_events(self, page=None): def get_events(self, page=None):
"""Fetch GitHub events.""" """Fetch GitHub events."""

16
main.py
View File

@ -1,16 +1,18 @@
"""GitMon""" """GitMon"""
import time
from loguru import logger
from gitmon.api import GitHubApi from gitmon.api import GitHubApi
from gitmon.logger import setup_logger from gitmon.logger import setup_logger
from config import token from config import token
def print_event(event): def log_event(event):
event_type = event.get('type') event_type = event.get('type')
repo = event.get('repo') repo = event.get('repo')
actor = event.get('actor') actor = event.get('actor')
print(f'{event_type}:\t{repo["name"]}, {actor["login"]}') logger.info(f'{event_type}:\t{repo["name"]}, {actor["login"]}')
def main(): def main():
@ -18,9 +20,13 @@ def main():
setup_logger() setup_logger()
api = GitHubApi(token) api = GitHubApi(token)
events = api.get_events() while True:
for event in events: events = api.get_events()
print_event(event) for event in events:
if event['type'] == 'CreateEvent':
log_event(event)
time.sleep(10)
if __name__ == '__main__': if __name__ == '__main__':