commit f0578f858b60682ef644acfd7757eaeffd5dee23 Author: Tony Date: Tue May 24 16:45:28 2022 -0500 initial commit diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..cfb257f --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..ffad4e2 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c069186 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/webcalDashboard.iml b/.idea/webcalDashboard.iml new file mode 100644 index 0000000..02d2170 --- /dev/null +++ b/.idea/webcalDashboard.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f2376b0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM tiangolo/uwsgi-nginx-flask:python3.8-alpine +RUN apk --update add bash nano +ENV STATIC_URL /static +ENV STATIC_PATH /var/www/app/static +COPY ./requirements.txt /var/www/requirements.txt +RUN pip install -r /var/www/requirements.txt \ No newline at end of file diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..8f5986d --- /dev/null +++ b/app/__init__.py @@ -0,0 +1,3 @@ +from flask import Flask +app = Flask(__name__) +from app import views \ No newline at end of file diff --git a/app/static/hellovetica.ttf b/app/static/hellovetica.ttf new file mode 100755 index 0000000..f9d262b Binary files /dev/null and b/app/static/hellovetica.ttf differ diff --git a/app/static/sun.gif b/app/static/sun.gif new file mode 100755 index 0000000..8312a02 Binary files /dev/null and b/app/static/sun.gif differ diff --git a/app/templates/dashboard.html b/app/templates/dashboard.html new file mode 100644 index 0000000..858cc16 --- /dev/null +++ b/app/templates/dashboard.html @@ -0,0 +1,118 @@ + + + + + + + +
+
+
+{# #} +
+
+ {{ today.strftime('%a') }}
+ {{ today.strftime('%b %-d') }}
+ {{ today.strftime('%Y') }}
+
+
+
+ + {% for day, event in days %} +
+
+ {{ day.strftime('%A') }} +
+ {% if event %} +
+ {{ event.summary.value }}
+ {% if event.dtstart.value.strftime('%H') != "00" %} + {{ event.dtstart.value.strftime('%-I:%M %p') }}
{{ event.dtend.value.strftime('%-I:%M %p') }} + {% endif %} +
+ {% endif %} +
+ {% endfor %} +
+
+ + diff --git a/app/views.py b/app/views.py new file mode 100644 index 0000000..327ea04 --- /dev/null +++ b/app/views.py @@ -0,0 +1,54 @@ +from app import app +from datetime import datetime, timedelta +import os +import caldav +import datetime +from icalendar import cal, Event +import requests +url = os.getenv('caldav_url') +username = os.getenv('username') +password = os.getenv('password') +cal_id = os.getenv('cal_id') + + +def daterange(start_date, end_date): + for n in range(int((end_date - start_date).days)): + yield datetime.datetime.date(start_date + timedelta(n)) + +@app.route('/') +def hello_world(): + date_obj = datetime.datetime.now() + + start_of_week = date_obj - timedelta(days=date_obj.weekday()) # Monday + end_of_week = start_of_week + timedelta(days=7) # Sunday + + with caldav.DAVClient(url=url, username=username, password=password) as client: + my_principal = client.principal() + + calendars = my_principal.calendars() + calendar = my_principal.calendar(cal_id=cal_id) + events_fetched = calendar.date_search( + start=start_of_week, end=end_of_week, expand=False) + + events_fetched_by_date = {} + for event in events_fetched: + value = event.vobject_instance.vevent.dtstart.value + if isinstance(value, datetime.datetime): + events_fetched_by_date[datetime.datetime.date(value)] = event + elif isinstance(value, datetime.date): + events_fetched_by_date[value] = event + else: + raise Exception + + days = [] + for single_date in daterange(start_of_week, end_of_week): + event = events_fetched_by_date.get(single_date) + if event: + days.append((single_date, event.vobject_instance.vevent)) + else: + days.append((single_date,[])) + + # breakpoint() + pass + # r = "
".join([event.vobject_instance.vevent.summary.value for event in events_fetched if event.vobject_instance.vevent.dtstart.value < datetime.now()]) + return render_template("dashboard.html", days=days, today=datetime.datetime.now()) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..e524e69 --- /dev/null +++ b/main.py @@ -0,0 +1 @@ +from app import app \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b0097ee --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +caldav~=0.9.0 +requests~=2.27.1 +icalendar~=4.0.9 +Flask~=2.1.2 \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..00f890b --- /dev/null +++ b/start.sh @@ -0,0 +1,6 @@ +#!/bin/bash +app="webcal-dashboard" +docker build -t ${app} . +docker run -d -p 56733:80 \ + --name=${app} \ + -v $PWD:/app ${app} \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..846ba67 --- /dev/null +++ b/test.py @@ -0,0 +1,28 @@ +import os +import caldav +from datetime import datetime +import requests +from icalendar import Calendar, cal, Event + +url = 'http://ical-cdn.teamsnap.com/team_schedule/5f1ddc9e-15b0-4912-84a2-11cc70e9e375.ics' +r = requests.get(url) +username = os.getenv('username') +password = os.getenv('password') +c = cal.Calendar.from_ical(r.content) + +calendar_ical = [{ + 'dtstart':e['DTSTART'].dt, + 'dtstart': e['DTEND'].dt, + 'summary': e['summary'] + } + for e in c.subcomponents + if isinstance(e, Event)] + +with caldav.DAVClient(url=url, username=username, password=password) as client: + my_principal = client.principal() + +calendars = my_principal.calendars() +calendar = my_principal.calendar(cal_id="9E2AC562-4328-4CA0-B4D1-D730D9F5E9EF") +events_fetched = calendar.date_search( + start=datetime(2022, 5, 23), end=datetime(2022, 5, 24), expand=True) +pass \ No newline at end of file diff --git a/uwsgi.ini b/uwsgi.ini new file mode 100644 index 0000000..1cf8434 --- /dev/null +++ b/uwsgi.ini @@ -0,0 +1,4 @@ +[uwsgi] +module = main +callable = app +master = true \ No newline at end of file