diff options
| author | Bobby <[email protected]> | 2024-02-11 21:49:51 -0500 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-02-11 21:49:51 -0500 |
| commit | 89d1ae0c3579112bd5ea1a868a1d95c7a75314c7 (patch) | |
| tree | 779edd953f8ce9b633e595846d3b6f5940f6bf4b | |
| parent | eecd7db0d9caff2131a4d1142a2cf0063acda3a8 (diff) | |
| download | thatcomputerscientist-89d1ae0c3579112bd5ea1a868a1d95c7a75314c7.tar.xz thatcomputerscientist-89d1ae0c3579112bd5ea1a868a1d95c7a75314c7.zip | |
Optimized image serving + bug fixes
| -rw-r--r-- | dev_status/utils.py | 12 | ||||
| -rw-r--r-- | dev_status/views.py | 6 | ||||
| -rw-r--r-- | ignis/views.py | 19 | ||||
| -rw-r--r-- | templates/dev_status/repo.html | 17 |
4 files changed, 38 insertions, 16 deletions
diff --git a/dev_status/utils.py b/dev_status/utils.py index f271e91b..02876dc5 100644 --- a/dev_status/utils.py +++ b/dev_status/utils.py @@ -8,17 +8,17 @@ def relative_date(entry): now = datetime.now() diff = now - committedDate if diff.days > 365: - entry["commit"]["committedDate"] = str(diff.days // 365) + " years ago" + entry["commit"]["committedDate"] = str(diff.days // 365) + " year" + ("s" if diff.days // 365 > 1 else "") + " ago" elif diff.days > 30: - entry["commit"]["committedDate"] = str(diff.days // 30) + " months ago" + entry["commit"]["committedDate"] = str(diff.days // 30) + " month" + ("s" if diff.days // 30 > 1 else "") + " ago" elif diff.days > 7: - entry["commit"]["committedDate"] = str(diff.days // 7) + " weeks ago" + entry["commit"]["committedDate"] = str(diff.days // 7) + " week" + ("s" if diff.days // 7 > 1 else "") + " ago" elif diff.days > 0: - entry["commit"]["committedDate"] = str(diff.days) + " days ago" + entry["commit"]["committedDate"] = str(diff.days) + " day" + ("s" if diff.days > 1 else "") + " ago" elif diff.seconds > 3600: - entry["commit"]["committedDate"] = str(diff.seconds // 3600) + " hours ago" + entry["commit"]["committedDate"] = str(diff.seconds // 3600) + " hour" + ("s" if diff.seconds // 3600 > 1 else "") + " ago" elif diff.seconds > 60: - entry["commit"]["committedDate"] = str(diff.seconds // 60) + " minutes ago" + entry["commit"]["committedDate"] = str(diff.seconds // 60) + " minute" + ("s" if diff.seconds // 60 > 1 else "") + " ago" else: entry["commit"]["committedDate"] = "just now" diff --git a/dev_status/views.py b/dev_status/views.py index b6329ee6..678be122 100644 --- a/dev_status/views.py +++ b/dev_status/views.py @@ -1,5 +1,6 @@ import math import os +import re import requests from django.shortcuts import render @@ -124,7 +125,6 @@ def get_repo(request, r=None, p=None): url = "https://api.github.com/graphql" headers = {"Authorization": "token " + os.getenv("GH_TOKEN")} parent = "/".join(p.split("/")[:-1]) if p and not len(p.split("/")) == 0 else None - print(parent, p) # get the contents of the repository along with the latest commit associated with each file or directory query = """ @@ -186,7 +186,9 @@ def get_repo(request, r=None, p=None): ) for entry in tree: - entry["uniquename"] = entry["path"].replace("/", "").replace(".", "") + # make path character only + entry["uniquename"] = re.sub(r"[^a-zA-Z]", "", entry["path"]) + query += """ {uniquename}: history(first: 1, path: "{path}") {{ nodes {{ diff --git a/ignis/views.py b/ignis/views.py index d6bd7faf..32c060e7 100644 --- a/ignis/views.py +++ b/ignis/views.py @@ -1,6 +1,6 @@ import json from io import BytesIO - +import os import requests from captcha.image import ImageCaptcha from django.core.files.base import ContentFile @@ -184,11 +184,28 @@ def socialify(request): url = 'https://socialify.thatcomputerscientist.com/{}/png?description={}&font={}&forks={}&issues={}&language={}&language2={}&name={}&owner=1&pattern={}&pulls={}&stargazers={}&theme={}'.format(repo, description, font, forks, issues, language_1, language_2, name, pattern, pulls, stargazers, theme) + image_unique_name = url.replace('https://socialify.thatcomputerscientist.com/', '').replace('/', '_') + image_path = 'images/repo_socialify_cache' + image_path = '{}/{}.png'.format(image_path, image_unique_name) + + if repo.split('/')[0] == 'luciferreeves': + if os.path.exists(image_path): + with open(image_path, 'rb') as f: + image = f.read() + return HttpResponse(image, content_type='image/png') + req = requests.get(url) image = req.content status = req.status_code if status == 200: + if not os.path.exists('images/repo_socialify_cache'): + os.makedirs('images/repo_socialify_cache') + + with open(image_path, 'wb') as f: + if repo.split('/')[0] == 'luciferreeves': + f.write(image) + return HttpResponse(image, content_type='image/png') else: with open('static/images/site/utgi.gif', 'rb') as f: diff --git a/templates/dev_status/repo.html b/templates/dev_status/repo.html index 83073fc4..7769b03f 100644 --- a/templates/dev_status/repo.html +++ b/templates/dev_status/repo.html @@ -13,8 +13,11 @@ style="display: inline-block; vertical-align: middle; height: 16px" /> </span> - <a href="{% if parent == '' %}{% url 'dev_status:repo' repo %}{% else %}{% url 'dev_status:repo-path' repo parent %}{% endif %}">..</a> - {% endif %} + <a + href="{% if parent == '' %}{% url 'dev_status:repo' repo %}{% else %}{% url 'dev_status:repo-path' repo parent %}{% endif %}" + >..</a + > + {% endif %} </p> {% if files and "byteSize" not in files %} <table id="file-list" width="100%"> @@ -46,14 +49,14 @@ /> </span> {% endif %} - <a href="{% url 'dev_status:repo-path' repo file.path %}">{{ file.name }}</a> + <a href="{% url 'dev_status:repo-path' repo file.path %}" + >{{ file.name }}</a + > </td> - <td>{{ file.commit.message }}</td> + <td>{{ file.commit.message|truncatechars:50 }}</td> <td>{{ file.commit.committedDate }}</td> </tr> {% endfor %} </tbody> </table> -{% endif %} - -{% endblock %} +{% endif %} {% endblock %} |
