touchups, fixed grammar and disabled debug

This commit is contained in:
2026-08-10 18:40:59 +02:00
parent f68cb56be6
commit d74fc2d85c
2 changed files with 21 additions and 22 deletions
+2 -2
View File
@@ -8,8 +8,8 @@ CALDAV_PASS=
# timezone. for example the default: Europe/Berlin
TIMEZONE=
# the intervall in which the calendar sessions will be re-read in minutes
REFETCH_INTERVALL_MINUTES=
# the interval in which the calendar sessions will be re-read in minutes
REFETCH_INTERVAL_MINUTES=
# an comma seperated list of semester starts.
# Studytime will only count sessions up to the last date in the past
+19 -20
View File
@@ -1,9 +1,21 @@
from flask import Flask, jsonify, render_template
import os, sys, threading, time
from src.parser import *
from src.parser import (
get_this_semesters_sessions,
calculate_totals,
get_last_n_days,
get_stats,
)
app = Flask(__name__)
REFETCH_MINUTES = os.environ.get("REFETCH_INTERVAL_MINUTES", "5")
if not REFETCH_MINUTES.isdigit():
print("Invalid refetch interval")
sys.exit(1)
REFETCH_SECONDS = int(REFETCH_MINUTES) * 60
# initial data fetch (required to work)
try:
sessions = get_this_semesters_sessions()
except Exception:
@@ -16,15 +28,9 @@ def index():
current = list(sessions)
labels = [s["subject"] for s in current]
values = [s["minutes"] for s in current]
return render_template(
"index.html",
labels=labels,
values=values,
sessions=current
)
return render_template("index.html", labels=labels, values=values, sessions=current)
# internal api
@app.route("/api/dashboard")
def api_dashboard():
current = list(sessions)
@@ -32,22 +38,20 @@ def api_dashboard():
return jsonify({
"sessions": current,
"subjectTotals": totals,
"dailyMinutes": get_last_n_days(50, current),
"dailyMinutes": get_last_n_days(50, current),
"stats": get_stats(current, totals),
})
# external api
@app.route("/api/sessions")
def api_sessions():
current = list(sessions)
return jsonify(current)
return jsonify(list(sessions))
# background daemon
def fetch_job():
global sessions
while True:
time.sleep(20) # 5 minutes
time.sleep(REFETCH_SECONDS)
try:
sessions = get_this_semesters_sessions()
print("Successfully fetched data from calDAV")
@@ -56,11 +60,6 @@ def fetch_job():
if __name__ == "__main__":
if os.environ.get("WERKZEUG_RUN_MAIN") == "true" or not app.debug:
# we need this guard because flask runs __main__ twice in debug mode
if not os.environ["REFETCH_INTERVALL_MINUTES"].isdigit():
print("Invalid refetch interval")
sys.exit(1)
t = threading.Thread(target=fetch_job, daemon=True)
t.start()
app.run(host="0.0.0.0", port=5000, debug=True)
app.run(host="0.0.0.0", port=5000, debug=False)