Last active
October 25, 2023 01:48
-
-
Save eonist/aadcdf0ca51b3d2c8992f94f600beb99 to your computer and use it in GitHub Desktop.
github_stats.py
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 json | |
import urllib.request | |
import ssl | |
username = input("Enter your GitHub username: ") | |
url = f"https://api.github.com/users/{username}/events" | |
context = ssl.create_default_context() | |
context.check_hostname = False | |
context.verify_mode = ssl.CERT_NONE | |
req = urllib.request.Request(url) | |
req.add_header("Accept", "application/vnd.github.v3+json") | |
with urllib.request.urlopen(req, context=context) as response: | |
events = json.loads(response.read()) | |
lines_added = 0 | |
lines_deleted = 0 | |
for event in events: | |
if event["type"] == "PushEvent": | |
for commit in event["payload"]["commits"]: | |
commit_url = commit["url"] | |
req = urllib.request.Request(commit_url) | |
req.add_header("Accept", "application/vnd.github.v3+json") | |
with urllib.request.urlopen(req, context=context) as response: | |
commit_data = json.loads(response.read()) | |
lines_added += commit_data["stats"]["additions"] | |
lines_deleted += commit_data["stats"]["deletions"] | |
print(f"Total lines of code added by {username}: {lines_added}") | |
print(f"Total lines of code deleted by {username}: {lines_deleted}") | |
net_lines_count = lines_added - lines_deleted | |
print(f"Net lines of code added by {username}: {net_lines_count}") | |
easy_life = {"min": 0, "max": 50} | |
hustler_mode = {"min": 50, "max": 200} | |
all_in_mode = {"min": 200, "max": 500} | |
ultra_mode = {"min": 500, "max": 5000} | |
mode_ranges = [easy_life, hustler_mode, all_in_mode, ultra_mode] | |
easy_life_mode_str = "🌴 Easy life mode 🌴" | |
hustler_mode_str = "🕺 Hustler mode 🕺" | |
all_in_mode_str = "💪 All in mode 💪" | |
ultra_mode_str = "😎 Ultra mode 😎" | |
mode_strings = [easy_life_mode_str, hustler_mode_str, all_in_mode_str, ultra_mode_str] | |
def check_mode(net_lines_count, mode_ranges): | |
for i, mode_range in enumerate(mode_ranges): | |
if net_lines_count >= mode_range["min"] and net_lines_count <= mode_range["max"]: | |
##print(f"Match found at index {i}") | |
print(f"Your 24h github mode is: {mode_strings[i]}") | |
return | |
##print("No match found") | |
check_mode(net_lines_count, mode_ranges) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is how the python script looks like in action: