fixes bugs in database calls
This commit is contained in:
parent
fe1c216c29
commit
b5cb35256c
19
Routine.py
19
Routine.py
@ -8,26 +8,17 @@ import json
|
|||||||
|
|
||||||
class Routine:
|
class Routine:
|
||||||
|
|
||||||
def start(self, time=10):
|
def updateCalendar(self, user, credentials):
|
||||||
self.updateCalendars()
|
|
||||||
|
|
||||||
|
|
||||||
def updateCalendar(self, user):
|
|
||||||
# check google:
|
# check google:
|
||||||
credentials = user.google_token
|
|
||||||
if credentials is None:
|
if credentials is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
visualCals = []
|
visualCals = []
|
||||||
calendars = db.session.query(Calendar).filter(Calendar.usr_id==user.id).all()
|
for calendar in user.calendars:
|
||||||
for calendar in calendars:
|
|
||||||
if calendar.toggle == 'True':
|
if calendar.toggle == 'True':
|
||||||
visualCals.append(calendar.calendar_id)
|
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)
|
googleCreds = google.oauth2.credentials.Credentials(**credentials)
|
||||||
calendarjson = caltojson.generateJsonFromCalendarEntries(visualCals, googleCreds)
|
calendarjson = caltojson.generateJsonFromCalendarEntries(visualCals, googleCreds)
|
||||||
user.setJson(calendarjson)
|
|
||||||
'''
|
'''
|
||||||
directory = 'userinfo/' + user.id + '/'
|
directory = 'userinfo/' + user.id + '/'
|
||||||
if not os.path.exists(directory):
|
if not os.path.exists(directory):
|
||||||
@ -35,13 +26,9 @@ class Routine:
|
|||||||
with open(directory + 'calendarevents.json', 'w', encoding='utf-8') as f:
|
with open(directory + 'calendarevents.json', 'w', encoding='utf-8') as f:
|
||||||
json.dump(calendarjson, f, ensure_ascii=False, indent=4)
|
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):
|
def credentials_to_dict(credentials):
|
||||||
return{'token': credentials.token,
|
return{'token': credentials.token,
|
||||||
'refresh_token': credentials.refresh_token,
|
'refresh_token': credentials.refresh_token,
|
||||||
|
Loading…
Reference in New Issue
Block a user