fixes bugs in database calls

This commit is contained in:
Raphael Maenle 2020-05-27 20:35:46 +02:00
parent fe1c216c29
commit b5cb35256c

View File

@ -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,