Skip to content

Commit 40c142a

Browse files
authored
Merge pull request #21 from tekktrik/dev/dark-and-cache
Add dark mode, image caching for GitHub card images
2 parents c92f2f2 + fffa363 commit 40c142a

13 files changed

+100
-6
lines changed

.github/workflows/publish.yml

+8
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,13 @@ jobs:
3434
pip install -r requirements.txt
3535
deactivate
3636
37+
# Update image cache instruction
38+
rm -rf .cron
39+
python3 -m venv .cron
40+
source .cron/bin/activate
41+
pip install --force-reinstall -r scripts/requirements.txt
42+
sh scripts/schedule_cache.sh
43+
deactivate
44+
3745
# Reload supervisor
3846
supervisorctl restart flask_app

.github/workflows/test_publish.yml

+8
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,13 @@ jobs:
3737
pip install -r requirements.txt
3838
deactivate
3939
40+
# Update image cache instruction
41+
rm -rf .cron
42+
python3 -m venv .cron
43+
source .cron/bin/activate
44+
pip install --force-reinstall -r scripts/requirements.txt
45+
sh scripts/schedule_cache.sh
46+
deactivate
47+
4048
# Reload supervisor
4149
supervisorctl start test_flask_app

.github/workflows/test_unpublish.yml

+8
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,13 @@ jobs:
3636
pip install -r requirements.txt
3737
deactivate
3838
39+
# Update image cache instruction
40+
rm -rf .cron
41+
python3 -m venv .cron
42+
source .cron/bin/activate
43+
pip install --force-reinstall -r scripts/requirements.txt
44+
sh scripts/schedule_cache.sh
45+
deactivate
46+
3947
# Stop supervisor
4048
supervisorctl stop test_flask_app

.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

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

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

scripts/schedule_cache.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+
REPOPATH=$(realpath .)
6+
JOBNAME=$(echo "$REPOPATH" | xargs basename)
7+
STATICPATH="$REPOPATH/flash_app/static"
8+
COMMAND="50 23 * * * python $SCRIPTPATH $REPOPATH"
9+
10+
cronberry enter "Cache cards for $JOBNAME" "$COMMAND" --overwrite

0 commit comments

Comments
 (0)