Last active
September 18, 2023 07:54
-
-
Save YOwatari/8c3f219806ed00033f157b2413ef2b07 to your computer and use it in GitHub Desktop.
The Amount of Code Written in Roughly One Month
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
import requests | |
from datetime import datetime, timedelta | |
TOKEN = "" | |
USERNAME = "" | |
one_month_ago = (datetime.now() - timedelta(days=30)).isoformat() | |
headers = { | |
"Authorization": f"token {TOKEN}", | |
"Accept": "application/vnd.github.v3+json" | |
} | |
def get_past_month_events(username, token): | |
page = 1 | |
events = [] | |
while True: | |
events_url = f"https://api.github.com/users/{username}/events?page={page}" | |
response = requests.get(events_url, headers=headers) | |
if response.status_code != 200: | |
break | |
page_data = response.json() | |
if not page_data: | |
break | |
filtered_data = [event for event in page_data if event['created_at'] > one_month_ago] | |
if not filtered_data: | |
break | |
events.extend(filtered_data) | |
page += 1 | |
return events | |
events = get_past_month_events(USERNAME, TOKEN) | |
total_additions = 0 | |
total_deletions = 0 | |
for event in events: | |
if event['type'] == "PushEvent": | |
for commit in event['payload']['commits']: | |
commit_url = commit['url'] | |
commit_response = requests.get(commit_url, headers=headers) | |
commit_data = commit_response.json() | |
total_additions += commit_data['stats']['additions'] | |
total_deletions += commit_data['stats']['deletions'] | |
print(f"Total additions in the last month from activity: {total_additions}") | |
print(f"Total deletions in the last month from activity: {total_deletions}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment