mirror of
https://github.com/marvinscham/marvinscham.git
synced 2025-12-06 10:10:47 +01:00
Temporarily removed waka projects from README
This commit is contained in:
@@ -2,30 +2,30 @@
|
|||||||
import base64
|
import base64
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
from dotenv import load_dotenv
|
|
||||||
from jinja2 import Environment, FileSystemLoader
|
|
||||||
import matplotlib.colors as mcolors
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import matplotlib.colors as mcolors
|
||||||
import pytz
|
import pytz
|
||||||
import requests
|
import requests
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
# Constants for the progress bar
|
# Constants for the progress bar
|
||||||
MAX_BAR_LENGTH = 40
|
MAX_BAR_LENGTH = 40
|
||||||
BAR_CHAR = '█'
|
BAR_CHAR = "█"
|
||||||
EMPTY_BAR_CHAR = '-'
|
EMPTY_BAR_CHAR = "-"
|
||||||
|
|
||||||
|
|
||||||
def hex_to_rgb(hex_color):
|
def hex_to_rgb(hex_color):
|
||||||
# Helper function to convert hex to RGB
|
# 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):
|
def shift_hue(obj, hue_shift):
|
||||||
# Shift hue to determine rainbow start
|
# 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:
|
if hue > 1:
|
||||||
hue -= 1.0
|
hue -= 1.0
|
||||||
return hue
|
return hue
|
||||||
@@ -33,7 +33,7 @@ def shift_hue(obj, hue_shift):
|
|||||||
|
|
||||||
def calc_darkness_bias(obj, threshold):
|
def calc_darkness_bias(obj, threshold):
|
||||||
# Threshold 1: No bias
|
# 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:
|
if brightness < threshold:
|
||||||
return 2 - brightness
|
return 2 - brightness
|
||||||
else:
|
else:
|
||||||
@@ -56,12 +56,11 @@ def seconds_to_string(seconds):
|
|||||||
return time_string
|
return time_string
|
||||||
|
|
||||||
|
|
||||||
resource_dir = os.path.join(os.path.dirname(
|
resource_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "resources")
|
||||||
os.path.abspath(__file__)), "resources")
|
|
||||||
env = Environment(loader=FileSystemLoader(resource_dir))
|
env = Environment(loader=FileSystemLoader(resource_dir))
|
||||||
|
|
||||||
# Load template
|
# Load template
|
||||||
template = env.get_template('README.md.jinja')
|
template = env.get_template("README.md.jinja")
|
||||||
|
|
||||||
# Load metadata files
|
# Load metadata files
|
||||||
with open(os.path.join(resource_dir, "technologies.json")) as f:
|
with open(os.path.join(resource_dir, "technologies.json")) as f:
|
||||||
@@ -77,15 +76,15 @@ darkness_bias = 0.2
|
|||||||
|
|
||||||
technologies = sorted(
|
technologies = sorted(
|
||||||
technologies,
|
technologies,
|
||||||
key=lambda obj: shift_hue(obj, hue_shift) +
|
key=lambda obj: shift_hue(obj, hue_shift) + calc_darkness_bias(obj, darkness_bias),
|
||||||
calc_darkness_bias(obj, darkness_bias)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
blog_entries = {}
|
blog_entries = {}
|
||||||
try:
|
try:
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
f"{os.getenv("GHOST_URL")}/ghost/api/content/posts/?key={os.getenv("GHOST_KEY")}")
|
f"{os.getenv("GHOST_URL")}/ghost/api/content/posts/?key={os.getenv("GHOST_KEY")}"
|
||||||
blog_entries = response.json()['posts'][:3]
|
)
|
||||||
|
blog_entries = response.json()["posts"][:3]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
pass
|
pass
|
||||||
@@ -93,11 +92,12 @@ except Exception as e:
|
|||||||
waka_projects = ""
|
waka_projects = ""
|
||||||
waka_langs = ""
|
waka_langs = ""
|
||||||
try:
|
try:
|
||||||
waka_token = base64.b64encode(
|
waka_token = base64.b64encode(os.getenv("WAKAPI_KEY").encode("ascii")).decode(
|
||||||
os.getenv("WAKAPI_KEY").encode("ascii")).decode("ascii")
|
"ascii"
|
||||||
|
)
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
f"{os.getenv("WAKAPI_URL")}/api/summary?interval=30_days",
|
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()
|
waka_info = response.json()
|
||||||
|
|
||||||
@@ -110,33 +110,36 @@ try:
|
|||||||
max_lang_len = max(len(entry["key"]) for entry in lang_list)
|
max_lang_len = max(len(entry["key"]) for entry in lang_list)
|
||||||
max_key_len = max(max_name_len, max_lang_len)
|
max_key_len = max(max_name_len, max_lang_len)
|
||||||
|
|
||||||
max_proj_time_len = max(len(seconds_to_string(
|
max_proj_time_len = max(
|
||||||
entry["total"])) for entry in project_list)
|
len(seconds_to_string(entry["total"])) for entry in project_list
|
||||||
|
)
|
||||||
max_lang_time_len = max(
|
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)
|
max_total_len = max(max_proj_time_len, max_lang_time_len)
|
||||||
|
|
||||||
waka_projects += "<pre>\n"
|
# waka_projects += "<pre>\n"
|
||||||
for project in project_list:
|
# for project in project_list:
|
||||||
filled_length = int(
|
# filled_length = int(
|
||||||
(project["total"] / total_duration) * MAX_BAR_LENGTH)
|
# (project["total"] / total_duration) * MAX_BAR_LENGTH)
|
||||||
progress_bar = BAR_CHAR * filled_length + \
|
# progress_bar = BAR_CHAR * filled_length + \
|
||||||
EMPTY_BAR_CHAR * (MAX_BAR_LENGTH - filled_length)
|
# EMPTY_BAR_CHAR * (MAX_BAR_LENGTH - filled_length)
|
||||||
percentage_str = str(
|
# percentage_str = str(
|
||||||
int((project["total"] / total_duration * 100))) + "%"
|
# int((project["total"] / total_duration * 100))) + "%"
|
||||||
|
|
||||||
waka_projects += f"{project['key']:<{max_key_len}} "
|
# waka_projects += f"{project['key']:<{max_key_len}} "
|
||||||
waka_projects += f"{seconds_to_string(project["total"]):>{
|
# waka_projects += f"{seconds_to_string(project["total"]):>{
|
||||||
max_total_len}} "
|
# max_total_len}} "
|
||||||
waka_projects += f"{progress_bar} "
|
# waka_projects += f"{progress_bar} "
|
||||||
waka_projects += f"{percentage_str:>3}\n"
|
# waka_projects += f"{percentage_str:>3}\n"
|
||||||
waka_projects += "</pre>"
|
# waka_projects += "</pre>"
|
||||||
|
|
||||||
waka_langs += "<pre>\n"
|
waka_langs += "<pre>\n"
|
||||||
for lang in lang_list:
|
for lang in lang_list:
|
||||||
filled_length = int((lang["total"] / total_duration) * MAX_BAR_LENGTH)
|
filled_length = int((lang["total"] / total_duration) * MAX_BAR_LENGTH)
|
||||||
progress_bar = BAR_CHAR * filled_length + \
|
progress_bar = BAR_CHAR * filled_length + EMPTY_BAR_CHAR * (
|
||||||
EMPTY_BAR_CHAR * (MAX_BAR_LENGTH - filled_length)
|
MAX_BAR_LENGTH - filled_length
|
||||||
|
)
|
||||||
percentage_str = str(int((lang["total"] / total_duration * 100))) + "%"
|
percentage_str = str(int((lang["total"] / total_duration * 100))) + "%"
|
||||||
|
|
||||||
waka_langs += f"{lang['key']:<{max_key_len}} "
|
waka_langs += f"{lang['key']:<{max_key_len}} "
|
||||||
@@ -157,7 +160,10 @@ try:
|
|||||||
duolingo_stats = response.json()
|
duolingo_stats = response.json()
|
||||||
|
|
||||||
for lang in duolingo_stats["lang_data"]:
|
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"]
|
current_lang = duolingo_stats["lang_data"][lang]["learningLanguageFull"]
|
||||||
|
|
||||||
duolingo_stats["current_lang"] = current_lang
|
duolingo_stats["current_lang"] = current_lang
|
||||||
@@ -165,26 +171,26 @@ except Exception as e:
|
|||||||
print(e)
|
print(e)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
berlin_timezone = pytz.timezone('Europe/Berlin')
|
berlin_timezone = pytz.timezone("Europe/Berlin")
|
||||||
berlin_time = datetime.datetime.now(berlin_timezone)
|
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
|
# Variables to pass to the template
|
||||||
data = {
|
data = {
|
||||||
"technologies": technologies,
|
"technologies": technologies,
|
||||||
"projects": projects,
|
"projects": projects,
|
||||||
"blog_entries": blog_entries,
|
"blog_entries": blog_entries,
|
||||||
"waka_stats": waka_stats,
|
"waka_stats": waka_stats,
|
||||||
"duolingo_stats": duolingo_stats,
|
"duolingo_stats": duolingo_stats,
|
||||||
"socials": socials,
|
"socials": socials,
|
||||||
"last_update": last_update
|
"last_update": last_update,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Render the template with data
|
# Render the template with data
|
||||||
output = template.render(data)
|
output = template.render(data)
|
||||||
|
|
||||||
# Write the output to README.md
|
# 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)
|
f.write(output)
|
||||||
|
|
||||||
print("README.md generated successfully.")
|
print("README.md generated successfully.")
|
||||||
|
|||||||
Reference in New Issue
Block a user