added the same dotenv config as the client and added a function to convert the loaded data into readable json for the frontend. Last sessions and the pie chart now work great!!
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
# full url. for example: https://calendar.com/user/study
|
||||
CALDAV_URL=
|
||||
|
||||
# CalDAV credentials
|
||||
CALDAV_USER=
|
||||
CALDAV_PASS=
|
||||
|
||||
# timezone. for example the default: Europe/Berlin
|
||||
TIMEZONE=
|
||||
+2
-14
@@ -1,21 +1,9 @@
|
||||
from flask import Flask, jsonify, render_template
|
||||
from src.fetch_sessions import get_events
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
sessions = [
|
||||
{ "subject": "Krypto", "minutes": 50, "ts": "26.03.2026 08:16" },
|
||||
{ "subject": "Netzwerke", "minutes": 40, "ts": "25.03.2026 19:02" },
|
||||
{ "subject": "Statistik", "minutes": 65, "ts": "25.03.2026 14:30" },
|
||||
{ "subject": "Krypto", "minutes": 30, "ts": "24.03.2026 09:12" },
|
||||
{ "subject": "Math", "minutes": 90, "ts": "23.03.2026 20:45" },
|
||||
{ "subject": "Databases", "minutes": 20, "ts": "23.03.2026 08:05" },
|
||||
{ "subject": "Krypto", "minutes": 50, "ts": "26.03.2026 08:16" },
|
||||
{ "subject": "Netzwerke", "minutes": 40, "ts": "25.03.2026 19:02" },
|
||||
{ "subject": "Statistik", "minutes": 65, "ts": "25.03.2026 14:30" },
|
||||
{ "subject": "Krypto", "minutes": 30, "ts": "24.03.2026 09:12" },
|
||||
{ "subject": "Math", "minutes": 90, "ts": "23.03.2026 20:45" },
|
||||
{ "subject": "Databases", "minutes": 20, "ts": "23.03.2026 08:05" },
|
||||
]
|
||||
sessions = get_events()
|
||||
|
||||
def calculate_totals(sessions):
|
||||
totals = {}
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,42 @@
|
||||
from dotenv import load_dotenv
|
||||
from zoneinfo import ZoneInfo
|
||||
import caldav, os
|
||||
|
||||
# load settings from .env
|
||||
try:
|
||||
load_dotenv()
|
||||
CALDAV_URL = os.environ["CALDAV_URL"]
|
||||
CALDAV_USER = os.environ["CALDAV_USER"]
|
||||
CALDAV_PASS = os.environ["CALDAV_PASS"]
|
||||
TIME_ZONE = ZoneInfo(os.environ.get("TIMEZONE", "Europe/Berlin"))
|
||||
except Exception:
|
||||
print("Failed to read settings from .env!\nTake a look at .env.example for the required structure!")
|
||||
|
||||
client = caldav.DAVClient(
|
||||
url=CALDAV_URL,
|
||||
username=CALDAV_USER,
|
||||
password=CALDAV_PASS,
|
||||
)
|
||||
calendar = client.calendar(url=CALDAV_URL)
|
||||
|
||||
|
||||
def get_events():
|
||||
events = calendar.events()
|
||||
events.sort(key=lambda e: e.vobject_instance.vevent.dtstart.value)
|
||||
|
||||
event_list = []
|
||||
for event in events:
|
||||
event.load() # fetch full data
|
||||
e = event.vobject_instance.vevent
|
||||
event_list.append({
|
||||
"subject":e.summary.value,
|
||||
"ts":e.dtstart.value.strftime("%d.%m.%Y %H:%M"),
|
||||
"minutes":int((e.dtend.value - e.dtstart.value).total_seconds() / 60)
|
||||
# "start":e.dtstart.value,
|
||||
# "end":e.dtend.value,
|
||||
})
|
||||
return event_list
|
||||
|
||||
|
||||
def get_sessions():
|
||||
events = get_events()
|
||||
Reference in New Issue
Block a user