Skip to content

Commit 83f60e4

Browse files
committed
Add dark mode, cache recent contributions
1 parent c92f2f2 commit 83f60e4

File tree

10 files changed

+74
-6
lines changed

10 files changed

+74
-6
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ __pycache__
99
venv
1010
.venv
1111
.env
12+
13+
# Project specific files
14+
flask_app/static/img/gh_cards/*.png
15+
assets/contrib/recent.json

flask_app/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ def project_menorah_settings() -> str:
8484
@app.route("/recent", methods=["GET"])
8585
def recent() -> str:
8686
"""Route for recent GitHub activity"""
87-
contributions, repos = get_repo_info(config["GH_TOKEN"])
87+
with open("assets/contrib/recent.json", encoding="utf-8") as respfile:
88+
contents = json.load(respfile)
89+
contributions, repos = contents["contributionsCollection"], contents["repositories"]
8890
end_datetime = dateutil.parser.parse(contributions["endedAt"])
8991
start_datetime = dateutil.parser.parse(contributions["startedAt"])
9092
diff_datetime: datetime.timedelta = end_datetime - start_datetime

flask_app/static/css/style.css

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ body > .container {
2020
padding: 100px 0;
2121
}
2222

23+
.layout-navbar {
24+
background-color: #000000;
25+
}
26+
2327
.navbar-brand {
2428
margin-left: 10px;
2529
margin-right: 5px;

flask_app/templates/layout/_footer.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
SPDX-License-Identifier: MIT
44
-->
55

6-
<footer class="sticky-footer bg-dark">
6+
<footer class="sticky-footer layout-navbar">
77
<div class="d-flex justify-content-center">
88
<p>
99
Designed with love myself:

flask_app/templates/layout/_header.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
<header>
8-
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
8+
<nav class="navbar navbar-expand-md navbar-dark fixed-top layout-navbar">
99
<a class="navbar-brand" href="/">
1010
<img src="/static/img/logo_dark.svg" width="50" height="50">
1111
Tekktrik Dev

flask_app/templates/layout/_layout.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-->
55

66
<!DOCTYPE html>
7-
<html>
7+
<html data-bs-theme="dark">
88
<head>
99
<meta charset="utf-8">
1010
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

flask_app/templates/recent.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
{% endif %}
2828
<div class="col-md-6">
2929
<div class="card recent-load-in" style="--delay: {{ loop.index0 * 0.2 }}s">
30-
<a href="{{ repo.url }}"><img src="{{ repo.openGraphImageUrl }}" class="card-img-top"/></a>
31-
<div class="card-body">
30+
<a href="{{ repo.url }}"><img src="/static/img/gh_cards/card{{ loop.index0 }}.png" class="card-img-top"/></a>
31+
<div class="card-body" style="background-color: white;">
3232
{% if repo.languages.nodes|length == 0 %}
3333
<span class="badge badge-other-language">Other</span>
3434
{% endif %}

scripts/graphql.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# SPDX-FileCopyrightText: 2023 Alec Delaney
2+
# SPDX-License-Identifier: MIT
3+
4+
"""Download the images from the GraphQL query to the static folder."""
5+
6+
import json
7+
import pathlib
8+
9+
import requests
10+
11+
URL = "https://api.github.com/graphql"
12+
13+
with open("/etc/config.json", encoding="utf-8") as jsonfile:
14+
config = json.load(jsonfile)
15+
16+
with open("assets/graphql_query.txt", mode="r", encoding="utf-8") as queryfile:
17+
query_param = {"query": queryfile.read()}
18+
19+
resp = requests.post(
20+
URL,
21+
json=query_param,
22+
headers={
23+
"Authorization": f'Bearer {config["GH_TOKEN"]}',
24+
},
25+
timeout=5,
26+
)
27+
28+
json_resp = json.loads(resp.content)["data"]["user"]
29+
resp_dir = pathlib.Path("assets/contrib/")
30+
card_dir = pathlib.Path("flask_app/static/img/gh_cards/")
31+
resp_dir.mkdir(exist_ok=True)
32+
card_dir.mkdir(exist_ok=True)
33+
34+
with open(str(resp_dir / "recent.json"), mode="w", encoding="utf-8") as contribfile:
35+
json.dump(json_resp, contribfile)
36+
37+
38+
for index, node in enumerate(json_resp["repositories"]["nodes"]):
39+
for _ in range(5):
40+
img_resp = requests.get(node["openGraphImageUrl"], timeout=5)
41+
if img_resp.status_code == 200:
42+
with open(str(card_dir / f"card{index}.png"), mode="wb") as imgfile:
43+
for data_chunk in img_resp:
44+
imgfile.write(data_chunk)

scripts/render_table.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
# SPDX-FileCopyrightText: 2023 Alec Delaney
3+
# SPDX-License-Identifier: MIT
4+
5+
SCRIPTPATH=$(realpath scripts/graphql.py)
6+
JOBNAME=$(realpath . | xargs dirname)
7+
STATICPATH=$(realpath flash_app/static)
8+
COMMAND="python $SCRIPTPATH $STATICPATH"
9+
10+
cronberry enter "Images for $JOBNAME" "$COMMAND" --overwrite

scripts/requirements.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPDX-FileCopyrightText: 2024 Alec Delaney
2+
# SPDX-License-Identifier: MIT
3+
4+
cronberry~=2.1

0 commit comments

Comments
 (0)