From b5cb35256cbecd125ff17c54ce983f850a31c705 Mon Sep 17 00:00:00 2001 From: Raphael Maenle Date: Wed, 27 May 2020 20:35:46 +0200 Subject: [PATCH] fixes bugs in database calls --- Routine.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/Routine.py b/Routine.py index 80bb99c..cdc3737 100644 --- a/Routine.py +++ b/Routine.py @@ -8,26 +8,17 @@ import json class Routine: - def start(self, time=10): - self.updateCalendars() - - - def updateCalendar(self, user): + def updateCalendar(self, user, credentials): # check google: - credentials = user.google_token if credentials is None: return visualCals = [] - calendars = db.session.query(Calendar).filter(Calendar.usr_id==user.id).all() - for calendar in calendars: + for calendar in user.calendars: if calendar.toggle == 'True': visualCals.append(calendar.calendar_id) - client_token = GC.build_credentials(user.google_token.token, - user.google_token.refresh_token) googleCreds = google.oauth2.credentials.Credentials(**credentials) calendarjson = caltojson.generateJsonFromCalendarEntries(visualCals, googleCreds) - user.setJson(calendarjson) ''' directory = 'userinfo/' + user.id + '/' if not os.path.exists(directory): @@ -35,13 +26,9 @@ class Routine: with open(directory + 'calendarevents.json', 'w', encoding='utf-8') as f: json.dump(calendarjson, f, ensure_ascii=False, indent=4) ''' + return calendarjson - def updateCalendars(self): - users = User.query.all() - for user in users: - self.updateCalendar(user) - def credentials_to_dict(credentials): return{'token': credentials.token, 'refresh_token': credentials.refresh_token,