Compare commits

..

No commits in common. "75ae245d40e69641ddcaaffc110dc3ade00b991b" and "bf34654a4668d788acc94e6462e6f0ef53af99ea" have entirely different histories.

4 changed files with 11 additions and 32 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 114 KiB

After

Width:  |  Height:  |  Size: 88 KiB

View File

@ -72,12 +72,9 @@ class GitHubApi:
headers (dict): The response headers from the GitHub API.
"""
try:
self.rate_reset = datetime.fromtimestamp(int(headers['x-ratelimit-reset']))
self.rate_remaining = int(headers['x-ratelimit-remaining'])
logger.info(f'{self.rate_remaining} calls remaining until {self.rate_reset} ({self.rate_reset - datetime.now()})')
except KeyError as e:
logger.warning(f'Could not parse headers: {str(e)}')
self.rate_reset = datetime.fromtimestamp(int(headers['x-ratelimit-reset']))
self.rate_remaining = int(headers['x-ratelimit-remaining'])
logger.info(f'{self.rate_remaining} calls remaining until {self.rate_reset} ({self.rate_reset - datetime.now()})')
def get_events(self, page=None):
"""Fetch GitHub events.

View File

@ -2,9 +2,6 @@
import sys
from loguru import logger
logger.level('CREATE', no=34, color='<green>')
logger.level('DELETE', no=35, color='<red>')
def setup_logger():
logger.remove()

31
main.py
View File

@ -1,5 +1,4 @@
"""GitMon"""
import signal
import time
from loguru import logger
from gitmon.api import GitHubApi
@ -17,37 +16,23 @@ def log_event(event):
actor = event.get('actor')
if event_type == 'DeleteEvent':
logger.log('DELETE', f'{event_type}:\thttps://github.com/{repo["name"]}, {actor["login"]}')
logger.error(f'{event_type}:\thttps://github.com/{repo["name"]}, {actor["login"]}')
else:
logger.log('CREATE', f'{event_type}:\thttps://github.com/{repo["name"]}, {actor["login"]}')
def sigint_handler(signum, frame):
"""Signal handler for Ctrl+C."""
raise KeyboardInterrupt
logger.info(f'{event_type}:\thttps://github.com/{repo["name"]}, {actor["login"]}')
def main():
"""Main entry point."""
# Setup logger and signal handling
setup_logger()
signal.signal(signal.SIGINT, sigint_handler)
api = GitHubApi(token)
try:
while True:
events = api.get_events()
for event in events:
if (
isinstance(event, dict)
and event.get('type') in ['CreateEvent', 'DeleteEvent']
):
log_event(event)
while True:
events = api.get_events()
for event in events:
if event['type'] in ['CreateEvent', 'DeleteEvent']:
log_event(event)
time.sleep(5)
except KeyboardInterrupt:
logger.info('Program terminating')
time.sleep(5)
if __name__ == '__main__':