From 9b4f4da2e3f543e488a3007369b31f8cacde58e4 Mon Sep 17 00:00:00 2001 From: KenwoodFox Date: Thu, 16 Jan 2025 12:02:53 -0500 Subject: [PATCH] Hit slightly lighter --- app/__init__.py | 4 ++++ app/filters/time_formatter.py | 20 ++++++++++++++++++++ app/routes/screens.py | 12 ++++++++++-- app/services/github_service.py | 5 ++++- app/static/styles/pending.css | 22 ++++++++++++++++++++++ app/static/styles/table.css | 22 ++++++++++++++++++++++ app/templates/pending.html | 3 +++ app/templates/table.html | 4 ++++ 8 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 app/filters/time_formatter.py diff --git a/app/__init__.py b/app/__init__.py index 47b5a44..b6523a7 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -5,12 +5,16 @@ from app.routes.index import index_bp from app.routes.screens import screens_bp +from app.filters.time_formatter import time_ago from app.services.github_service import GitHubService app = Flask(__name__) +# Filters +app.jinja_env.filters["time_ago"] = time_ago + def create_app(): # Register Blueprints diff --git a/app/filters/time_formatter.py b/app/filters/time_formatter.py new file mode 100644 index 0000000..ddfaab5 --- /dev/null +++ b/app/filters/time_formatter.py @@ -0,0 +1,20 @@ +from flask import Flask +from datetime import datetime + + +def time_ago(dt): + if dt is None: + return "Never updated" + + now = datetime.now() + delta = now - dt + seconds = delta.total_seconds() + + if seconds < 60: + return f"{int(seconds)} seconds ago" + elif seconds < 3600: + return f"{int(seconds // 60)} minute(s) ago" + elif seconds < 86400: + return f"{int(seconds // 3600)} hour(s) ago" + else: + return f"{int(seconds // 86400)} day ago" diff --git a/app/routes/screens.py b/app/routes/screens.py index 042ace3..3893d3a 100644 --- a/app/routes/screens.py +++ b/app/routes/screens.py @@ -43,9 +43,17 @@ def test_screen(): @screens_bp.route("/pending") def pending_screen(): - return render_template("pending.html", **app.github_service.latest_data) + return render_template( + "pending.html", + **app.github_service.latest_data, + last_updated=app.github_service.last_updated, + ) @screens_bp.route("/table") def table_screen(): - return render_template("table.html", **app.github_service.latest_data) + return render_template( + "table.html", + **app.github_service.latest_data, + last_updated=app.github_service.last_updated, + ) diff --git a/app/services/github_service.py b/app/services/github_service.py index 15e78fc..7ca8bbe 100644 --- a/app/services/github_service.py +++ b/app/services/github_service.py @@ -1,5 +1,6 @@ import time import threading +from datetime import datetime from github import Github @@ -21,6 +22,7 @@ def __init__(self, token, repos, username_mapping): "pull_requests_count": 0, "pending_reviews": [], } + self.last_updated = None def fetch_data(self): """Main loop for updating GitHub data.""" @@ -29,8 +31,9 @@ def fetch_data(self): self.update_pending_reviews() print("Updated github data.") + self.last_updated = datetime.now() - time.sleep(90) + time.sleep(120) def get_mapped_username(self, username): return self.username_mapping.get(username, username) diff --git a/app/static/styles/pending.css b/app/static/styles/pending.css index a789f8c..e7a1cb8 100644 --- a/app/static/styles/pending.css +++ b/app/static/styles/pending.css @@ -88,6 +88,28 @@ body { border: 2px solid #ffa500; } +/* ====== */ +/* Footer */ +/* ====== */ +.page-footer { + position: fixed; + bottom: 10px; + left: 10px; + font-size: 0.9em; + color: #aaa; + background: #333; + padding: 5px 10px; + border-radius: 5px; + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5); + z-index: 1000; /* Ensure it stays above other elements */ + font-family: "Courier New", Courier, monospace; +} + +.page-footer a { + color: #ffa500; /* Link color */ + text-decoration: none; +} + /* Flashing Animation */ @keyframes flash { from { diff --git a/app/static/styles/table.css b/app/static/styles/table.css index 4320a42..cd513a9 100644 --- a/app/static/styles/table.css +++ b/app/static/styles/table.css @@ -260,6 +260,28 @@ body { color: #f44336; } +/* ====== */ +/* Footer */ +/* ====== */ +.page-footer { + position: fixed; + bottom: 10px; + left: 10px; + font-size: 0.9em; + color: #aaa; + background: #333; + padding: 5px 10px; + border-radius: 5px; + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5); + z-index: 1000; /* Ensure it stays above other elements */ + font-family: "Courier New", Courier, monospace; +} + +.page-footer a { + color: #ffa500; /* Link color */ + text-decoration: none; +} + /* ====== */ /* Labels */ /* ====== */ diff --git a/app/templates/pending.html b/app/templates/pending.html index 27b5c5c..fb12694 100644 --- a/app/templates/pending.html +++ b/app/templates/pending.html @@ -23,6 +23,9 @@ {% endfor %} + \ No newline at end of file diff --git a/app/templates/table.html b/app/templates/table.html index 65ad4be..16c57be 100644 --- a/app/templates/table.html +++ b/app/templates/table.html @@ -117,6 +117,10 @@

Pull Requests ({{ pull_requests_count }})

+ + \ No newline at end of file