Skip to content

Instantly share code, notes, and snippets.

@eonist
Last active October 25, 2023 01:48
Show Gist options
  • Save eonist/aadcdf0ca51b3d2c8992f94f600beb99 to your computer and use it in GitHub Desktop.
Save eonist/aadcdf0ca51b3d2c8992f94f600beb99 to your computer and use it in GitHub Desktop.
github_stats.py
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)
@eonist
Copy link
Author

eonist commented Sep 27, 2023

Or check out the mini book im writing on prompt coding: https://gist.github.com/eonist/22e7458f9b38424af9d1bfd791b796a4

@eonist
Copy link
Author

eonist commented Sep 29, 2023

Here is how the python script looks like in action:

img

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment