diff --git a/backend b/backend index fec09ed..056779f 160000 --- a/backend +++ b/backend @@ -1 +1 @@ -Subproject commit fec09edb888013c5cb9c062d5cdb2220bc1a217d +Subproject commit 056779f7d26746cf54e73156e0a3909ecf058298 diff --git a/docker/calendarwatch/Dockerfile b/docker/calendarwatch/Dockerfile index 504bedd..d4ef413 100644 --- a/docker/calendarwatch/Dockerfile +++ b/docker/calendarwatch/Dockerfile @@ -2,7 +2,7 @@ FROM python:3.8-slim-buster RUN apt-get update && apt-get upgrade RUN pip3 install flask Flask-SQLAlchemy flask_migrate flask_login flask_wtf python-dotenv RUN apt-get install gcc libpcre3 libpcre3-dev libmariadbclient-dev -y -RUN pip3 install uwsgi email-validator RandomWords icalevents +RUN pip3 install uwsgi email-validator RandomWords ics RUN pip3 install google google-oauth google-auth-oauthlib google-api-python-client mysqlclient COPY docker-entrypoint.sh /usr/local/bin/ EXPOSE 8084 diff --git a/server/forms.py b/server/forms.py index 6abe9d0..e39d4f8 100644 --- a/server/forms.py +++ b/server/forms.py @@ -50,6 +50,7 @@ class DeviceForm(FlaskForm): class CalendarForm(FlaskForm): iCalURL = StringField('New ical URL', validators=[DataRequired()]) + calName = StringField('Calendar Name', validators=[DataRequired()]) submit = SubmitField('Add URL') def validate_iCalURL (self, iCalURL): diff --git a/server/googleHandler.py b/server/googleHandler.py index 03879f0..2b92194 100644 --- a/server/googleHandler.py +++ b/server/googleHandler.py @@ -121,19 +121,23 @@ def deleteAccount(user): def fetchCalendarEvents(user, calendars, startDate, endDate): + + service = None + if user.google_token is not None: + client_token = GC.build_credentials(user.google_token.token, + user.google_token.refresh_token) + credentials = google.oauth2.credentials.Credentials(**client_token) - client_token = GC.build_credentials(user.google_token.token, - user.google_token.refresh_token) - credentials = google.oauth2.credentials.Credentials(**client_token) - - service = build(GC.API_SERVICE_NAME, GC.API_VERSION, credentials=credentials) + service = build(GC.API_SERVICE_NAME, GC.API_VERSION, credentials=credentials) all_events = [] for calendar in calendars: - if calendar.toggle == "True" and calendar.calType == "Google": + if (calendar.toggle == "True" and + calendar.calendar_type == "Google" and + service != None): event_result = service.events().list(calendarId=calendar.calendar_id, - timeMin=startDate, - timeMax=endDate, + timeMin=startDate.isoformat(), + timeMax=endDate.isoformat(), maxResults=10, singleEvents=True, orderBy='startTime').execute() @@ -156,7 +160,10 @@ def fetchCalendarEvents(user, calendars, startDate, endDate): all_events.append(newEvent) - colors = service.colors().get().execute() + if service != None: + colors = service.colors().get().execute() + else: + colors = None return all_events, colors diff --git a/server/routes.py b/server/routes.py index 3c1817a..8058ef4 100644 --- a/server/routes.py +++ b/server/routes.py @@ -17,6 +17,7 @@ from flask_login import ( from random_words import RandomWords import requests +import backend.icalHandler as ical import server.googleHandler as google from server import login_manager, app, db @@ -105,6 +106,9 @@ def calendar(): if form.validate_on_submit(): # try to add the submitted ical as a calendar print(form.iCalURL.data, flush=True) + + + ical.icalToCalendarDb(form.iCalURL.data, form.calName.data, current_user) # otherwise it is a javascript POST else: @@ -255,6 +259,7 @@ def downloader(device): # TODO only pass along google calendars form user startDate, endDate = backend.getTimeStamps() events, colors = google.fetchCalendarEvents(request_user, request_user.calendars, startDate, endDate) + events.extend(ical.fetchCalendarEvents(request_user.calendars, startDate, endDate)) calendarjson = backend.generateJsonFromCalendarEntries(events, colors) return jsonify(calendarjson) diff --git a/server/template/calendar.html b/server/template/calendar.html index 9b5ba1f..d30ebfa 100644 --- a/server/template/calendar.html +++ b/server/template/calendar.html @@ -36,6 +36,8 @@
{{ form.hidden_tag() }}
+
{{ form.calName.label }}
+
{{ form.calName(size=24) }}
{{ form.iCalURL.label }}
{{ form.iCalURL(size=24) }}
{{ form.submit() }}