adds regular processing script whichs writes to database in server

This commit is contained in:
Raphael Maenle 2020-04-24 18:23:47 +00:00
parent aaf66a1f10
commit 8d546e37a8
6 changed files with 36 additions and 3 deletions

33
Routine.py Normal file
View File

@ -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()

3
__init__.py Normal file
View File

@ -0,0 +1,3 @@
from backend.Routine import Routine
routine = Routine()

View File

@ -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}}}]}

View File

@ -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"}]}

View File

@ -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"]}}

Binary file not shown.