mirror of
https://git.juggalol.com/agatha/gitmon.git
synced 2024-11-21 23:16:41 +00:00
Compare commits
6 Commits
bf34654a46
...
75ae245d40
Author | SHA1 | Date | |
---|---|---|---|
75ae245d40 | |||
1c6a45a1d2 | |||
1e958b397a | |||
e4a153d385 | |||
f599911998 | |||
73e5a63565 |
Binary file not shown.
Before Width: | Height: | Size: 88 KiB After Width: | Height: | Size: 114 KiB |
@ -72,9 +72,12 @@ class GitHubApi:
|
|||||||
headers (dict): The response headers from the GitHub API.
|
headers (dict): The response headers from the GitHub API.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.rate_reset = datetime.fromtimestamp(int(headers['x-ratelimit-reset']))
|
try:
|
||||||
self.rate_remaining = int(headers['x-ratelimit-remaining'])
|
self.rate_reset = datetime.fromtimestamp(int(headers['x-ratelimit-reset']))
|
||||||
logger.info(f'{self.rate_remaining} calls remaining until {self.rate_reset} ({self.rate_reset - datetime.now()})')
|
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)}')
|
||||||
|
|
||||||
def get_events(self, page=None):
|
def get_events(self, page=None):
|
||||||
"""Fetch GitHub events.
|
"""Fetch GitHub events.
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
import sys
|
import sys
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
|
logger.level('CREATE', no=34, color='<green>')
|
||||||
|
logger.level('DELETE', no=35, color='<red>')
|
||||||
|
|
||||||
|
|
||||||
def setup_logger():
|
def setup_logger():
|
||||||
logger.remove()
|
logger.remove()
|
||||||
|
31
main.py
31
main.py
@ -1,4 +1,5 @@
|
|||||||
"""GitMon"""
|
"""GitMon"""
|
||||||
|
import signal
|
||||||
import time
|
import time
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from gitmon.api import GitHubApi
|
from gitmon.api import GitHubApi
|
||||||
@ -16,23 +17,37 @@ def log_event(event):
|
|||||||
actor = event.get('actor')
|
actor = event.get('actor')
|
||||||
|
|
||||||
if event_type == 'DeleteEvent':
|
if event_type == 'DeleteEvent':
|
||||||
logger.error(f'{event_type}:\thttps://github.com/{repo["name"]}, {actor["login"]}')
|
logger.log('DELETE', f'{event_type}:\thttps://github.com/{repo["name"]}, {actor["login"]}')
|
||||||
else:
|
else:
|
||||||
logger.info(f'{event_type}:\thttps://github.com/{repo["name"]}, {actor["login"]}')
|
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
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main entry point."""
|
"""Main entry point."""
|
||||||
|
# Setup logger and signal handling
|
||||||
setup_logger()
|
setup_logger()
|
||||||
|
signal.signal(signal.SIGINT, sigint_handler)
|
||||||
|
|
||||||
api = GitHubApi(token)
|
api = GitHubApi(token)
|
||||||
|
|
||||||
while True:
|
try:
|
||||||
events = api.get_events()
|
while True:
|
||||||
for event in events:
|
events = api.get_events()
|
||||||
if event['type'] in ['CreateEvent', 'DeleteEvent']:
|
for event in events:
|
||||||
log_event(event)
|
if (
|
||||||
|
isinstance(event, dict)
|
||||||
|
and event.get('type') in ['CreateEvent', 'DeleteEvent']
|
||||||
|
):
|
||||||
|
log_event(event)
|
||||||
|
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
logger.info('Program terminating')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user