diff --git a/readme_updater.py b/readme_updater.py index faa4340..696a48c 100644 --- a/readme_updater.py +++ b/readme_updater.py @@ -2,30 +2,30 @@ import base64 import datetime import json -from dotenv import load_dotenv -from jinja2 import Environment, FileSystemLoader -import matplotlib.colors as mcolors import os +import matplotlib.colors as mcolors import pytz import requests +from dotenv import load_dotenv +from jinja2 import Environment, FileSystemLoader load_dotenv() # Constants for the progress bar MAX_BAR_LENGTH = 40 -BAR_CHAR = '█' -EMPTY_BAR_CHAR = '-' +BAR_CHAR = "█" +EMPTY_BAR_CHAR = "-" def hex_to_rgb(hex_color): # Helper function to convert hex to RGB - return tuple(int(hex_color[i:i+2], 16) / 255.0 for i in (1, 3, 5)) + return tuple(int(hex_color[i : i + 2], 16) / 255.0 for i in (1, 3, 5)) def shift_hue(obj, hue_shift): # Shift hue to determine rainbow start - hue = mcolors.rgb_to_hsv(hex_to_rgb(obj['color']))[0] + hue_shift + hue = mcolors.rgb_to_hsv(hex_to_rgb(obj["color"]))[0] + hue_shift if hue > 1: hue -= 1.0 return hue @@ -33,7 +33,7 @@ def shift_hue(obj, hue_shift): def calc_darkness_bias(obj, threshold): # Threshold 1: No bias - brightness = mcolors.rgb_to_hsv(hex_to_rgb(obj['color']))[2] + brightness = mcolors.rgb_to_hsv(hex_to_rgb(obj["color"]))[2] if brightness < threshold: return 2 - brightness else: @@ -56,12 +56,11 @@ def seconds_to_string(seconds): return time_string -resource_dir = os.path.join(os.path.dirname( - os.path.abspath(__file__)), "resources") +resource_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "resources") env = Environment(loader=FileSystemLoader(resource_dir)) # Load template -template = env.get_template('README.md.jinja') +template = env.get_template("README.md.jinja") # Load metadata files with open(os.path.join(resource_dir, "technologies.json")) as f: @@ -77,15 +76,15 @@ darkness_bias = 0.2 technologies = sorted( technologies, - key=lambda obj: shift_hue(obj, hue_shift) + - calc_darkness_bias(obj, darkness_bias) + key=lambda obj: shift_hue(obj, hue_shift) + calc_darkness_bias(obj, darkness_bias), ) blog_entries = {} try: response = requests.get( - f"{os.getenv("GHOST_URL")}/ghost/api/content/posts/?key={os.getenv("GHOST_KEY")}") - blog_entries = response.json()['posts'][:3] + f"{os.getenv("GHOST_URL")}/ghost/api/content/posts/?key={os.getenv("GHOST_KEY")}" + ) + blog_entries = response.json()["posts"][:3] except Exception as e: print(e) pass @@ -93,11 +92,12 @@ except Exception as e: waka_projects = "" waka_langs = "" try: - waka_token = base64.b64encode( - os.getenv("WAKAPI_KEY").encode("ascii")).decode("ascii") + waka_token = base64.b64encode(os.getenv("WAKAPI_KEY").encode("ascii")).decode( + "ascii" + ) response = requests.get( f"{os.getenv("WAKAPI_URL")}/api/summary?interval=30_days", - headers={'Authorization': f"Basic {waka_token}"} + headers={"Authorization": f"Basic {waka_token}"}, ) waka_info = response.json() @@ -110,33 +110,36 @@ try: max_lang_len = max(len(entry["key"]) for entry in lang_list) max_key_len = max(max_name_len, max_lang_len) - max_proj_time_len = max(len(seconds_to_string( - entry["total"])) for entry in project_list) + max_proj_time_len = max( + len(seconds_to_string(entry["total"])) for entry in project_list + ) max_lang_time_len = max( - len(seconds_to_string(entry["total"])) for entry in lang_list) + len(seconds_to_string(entry["total"])) for entry in lang_list + ) max_total_len = max(max_proj_time_len, max_lang_time_len) - waka_projects += "
\n"
- for project in project_list:
- filled_length = int(
- (project["total"] / total_duration) * MAX_BAR_LENGTH)
- progress_bar = BAR_CHAR * filled_length + \
- EMPTY_BAR_CHAR * (MAX_BAR_LENGTH - filled_length)
- percentage_str = str(
- int((project["total"] / total_duration * 100))) + "%"
+ # waka_projects += "\n"
+ # for project in project_list:
+ # filled_length = int(
+ # (project["total"] / total_duration) * MAX_BAR_LENGTH)
+ # progress_bar = BAR_CHAR * filled_length + \
+ # EMPTY_BAR_CHAR * (MAX_BAR_LENGTH - filled_length)
+ # percentage_str = str(
+ # int((project["total"] / total_duration * 100))) + "%"
- waka_projects += f"{project['key']:<{max_key_len}} "
- waka_projects += f"{seconds_to_string(project["total"]):>{
- max_total_len}} "
- waka_projects += f"{progress_bar} "
- waka_projects += f"{percentage_str:>3}\n"
- waka_projects += ""
+ # waka_projects += f"{project['key']:<{max_key_len}} "
+ # waka_projects += f"{seconds_to_string(project["total"]):>{
+ # max_total_len}} "
+ # waka_projects += f"{progress_bar} "
+ # waka_projects += f"{percentage_str:>3}\n"
+ # waka_projects += ""
waka_langs += "\n"
for lang in lang_list:
filled_length = int((lang["total"] / total_duration) * MAX_BAR_LENGTH)
- progress_bar = BAR_CHAR * filled_length + \
- EMPTY_BAR_CHAR * (MAX_BAR_LENGTH - filled_length)
+ progress_bar = BAR_CHAR * filled_length + EMPTY_BAR_CHAR * (
+ MAX_BAR_LENGTH - filled_length
+ )
percentage_str = str(int((lang["total"] / total_duration * 100))) + "%"
waka_langs += f"{lang['key']:<{max_key_len}} "
@@ -157,7 +160,10 @@ try:
duolingo_stats = response.json()
for lang in duolingo_stats["lang_data"]:
- if duolingo_stats["lang_data"][lang]["learningLanguage"] == duolingo_stats["learning_language"]:
+ if (
+ duolingo_stats["lang_data"][lang]["learningLanguage"]
+ == duolingo_stats["learning_language"]
+ ):
current_lang = duolingo_stats["lang_data"][lang]["learningLanguageFull"]
duolingo_stats["current_lang"] = current_lang
@@ -165,26 +171,26 @@ except Exception as e:
print(e)
pass
-berlin_timezone = pytz.timezone('Europe/Berlin')
+berlin_timezone = pytz.timezone("Europe/Berlin")
berlin_time = datetime.datetime.now(berlin_timezone)
-last_update = berlin_time.strftime('%A, %e %B %H:%M %Z')
+last_update = berlin_time.strftime("%A, %e %B %H:%M %Z")
# Variables to pass to the template
data = {
"technologies": technologies,
"projects": projects,
- "blog_entries": blog_entries,
+ "blog_entries": blog_entries,
"waka_stats": waka_stats,
"duolingo_stats": duolingo_stats,
"socials": socials,
- "last_update": last_update
+ "last_update": last_update,
}
# Render the template with data
output = template.render(data)
# Write the output to README.md
-with open('README.md', 'w', encoding='utf-8') as f:
+with open("README.md", "w", encoding="utf-8") as f:
f.write(output)
print("README.md generated successfully.")