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 23, 2023

Here is the prompt code strategy to add the 24h GitHub streak badge feature

Here is our starting point: https://gist.github.com/eonist/22e7458f9b38424af9d1bfd791b796a4#Strategy

Step 1

can we define a few range variables 0-50, 50-200,200-500, 500-5000 and name these ranges easy_life, hustler_mode, all_in_mode, ultra_mode

step 2

can you also define variables by the same names with empty string as value?

step 3

create a string variable name easy_life_str with an empty string

step 4

take the variable name in each line and add it to the string value

step 5

make an array with each of the selected variables

step 6

make a method that checks if the net_lines_count is within the range of each variable in mode_ranges array. If it is with a range print the index the match was found

step 7

create a print call that used the i variable and gets a value at the i index from the mode_strings array. Prefix the print with "Your 24h github mode is: "

step 8

add some apropriate emoijies to the strings

step 9

can we use some funnier emoji?

step 10

call the check_mode method

@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