From 8d546e37a890846313e62d1392a09956d109794a Mon Sep 17 00:00:00 2001 From: raphael Date: Fri, 24 Apr 2020 18:23:47 +0000 Subject: [PATCH] adds regular processing script whichs writes to database in server --- Routine.py | 33 +++++++++++++++++++++++++++++++++ __init__.py | 3 +++ calendarevents.json | 1 - calendars.json | 1 - credentials.json | 1 - token.pickle2 | Bin 752 -> 0 bytes 6 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 Routine.py create mode 100644 __init__.py delete mode 100644 calendarevents.json delete mode 100644 calendars.json delete mode 100644 credentials.json delete mode 100644 token.pickle2 diff --git a/Routine.py b/Routine.py new file mode 100644 index 0000000..2e01338 --- /dev/null +++ b/Routine.py @@ -0,0 +1,33 @@ +from server import db +from server.models import User +from backend import caltojson + +import google.oauth2.credentials +import json + +class Routine: + + def start(self, time=10): + self.updateCalendars() + + + def updateCalendars(self): + users = User.query.all() + for user in users: + # check google: + credentials = user.getGoogleCredentials() + if credentials is None: + continue + + credentials = google.oauth2.credentials.Credentials(**credentials) + calendarjson = caltojson.generateJsonFromCalendarEntries(credentials) + + user.setJson(calendarjson) + + with open('userinfo/'+ user.id +'/calendarevents.json', 'w', encoding='utf-8') as f: + json.dump(calendarjson, f, ensure_ascii=False, indent=4) + + +if __name__ == "__main__": + routine = Routine() + routine.start() diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..aa54bf7 --- /dev/null +++ b/__init__.py @@ -0,0 +1,3 @@ +from backend.Routine import Routine + +routine = Routine() diff --git a/calendarevents.json b/calendarevents.json deleted file mode 100644 index b34de3f..0000000 --- a/calendarevents.json +++ /dev/null @@ -1 +0,0 @@ -{"kind": "calendar#events", "events": [{"name": "Sleep", "isAllDay": false, "color": "#616161", "startDateTime": {"date": {"year": 2020, "month": 3, "day": 28}, "time": {"hour": 0, "minute": 0, "second": 0}}, "stopDateTime": {"date": {"year": 2020, "month": 3, "day": 28}, "time": {"hour": 8, "minute": 0, "second": 0}}}, {"name": "Sleep", "isAllDay": false, "color": "#616161", "startDateTime": {"date": {"year": 2020, "month": 3, "day": 29}, "time": {"hour": 0, "minute": 0, "second": 0}}, "stopDateTime": {"date": {"year": 2020, "month": 3, "day": 29}, "time": {"hour": 8, "minute": 0, "second": 0}}}]} \ No newline at end of file diff --git a/calendars.json b/calendars.json deleted file mode 100644 index 4306185..0000000 --- a/calendars.json +++ /dev/null @@ -1 +0,0 @@ -{"calendars": [{"name": "Todoist"}, {"name": "https://intranet.fhwn.ac.at/ics/Default.aspx?FHTimetable.ics&id=YUWSjNJUx5I%3d&datediffmonths=1&replaceSpecialChars=1"}, {"name": "Hightower"}, {"name": "Home \ud83c\udfe0"}, {"name": "D-ARIA"}, {"name": "Office"}, {"name": "http://followshows.com/ical/AS3Bbq0q"}, {"name": "Grey"}, {"name": "Privat"}, {"name": "Work"}, {"name": "Social"}, {"name": "Life"}, {"name": "https://poledancevienna.at/mypdv/ical/XJSY-56GQ-G2VC"}, {"name": "Contacts"}, {"name": "Holidays in Austria"}, {"name": "Week Numbers"}]} \ No newline at end of file diff --git a/credentials.json b/credentials.json deleted file mode 100644 index 7e38ee5..0000000 --- a/credentials.json +++ /dev/null @@ -1 +0,0 @@ -{"installed":{"client_id":"590778864034-e3gjrjk8csdu2mee29dpe3mkql419no9.apps.googleusercontent.com","project_id":"quickstart-1583661954000","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"kj-suDOOuYQ3M4RpYG2exHyK","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}} diff --git a/token.pickle2 b/token.pickle2 deleted file mode 100644 index 5552e0a79c1b46a8e1e1ddb31390fd5528bddf40..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 752 zcmZ8fO>@#v6vft-7PVTfjth5gbdf;5fVc~g6iWFh6#CK`C-X=i`6S7Ec_F}zGrI8C z__zEKE)9ioI_}P#nS1Uz_nz;ErX59gfY=D8)Ztl^APa@mg+WqkKEk;0`3HXT4Ig|0 zM};H==Yk-1Kc; zbC+3r)bRPvL|kh_o$5xaE*aCfuMV_isEP(AwHcF+bz`JTdIiBoqb8Yk{1hDLj?pT1 z$r>M-7Nm%}3sm|C@Nu(L{C)VLbZ}DqbAgLL@yQ6Eg0peWe-0Cr&|lIwcq}{4~knNF{2nI_{CRz2DqGX zD2eg!^0QrZ{e zKe62n&Ud3`;O3pl&EeOeosUX#rB