43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
from server import db
|
|
from database.models import User, Calendar
|
|
from backend import caltojson
|
|
import os
|
|
|
|
import google.oauth2.credentials
|
|
import json
|
|
|
|
class Routine:
|
|
|
|
def updateCalendar(self, user, credentials):
|
|
# check google:
|
|
if credentials is None:
|
|
return
|
|
|
|
visualCals = []
|
|
for calendar in user.calendars:
|
|
if calendar.toggle == 'True':
|
|
visualCals.append(calendar.calendar_id)
|
|
googleCreds = google.oauth2.credentials.Credentials(**credentials)
|
|
calendarjson = caltojson.generateJsonFromCalendarEntries(visualCals, googleCreds)
|
|
'''
|
|
directory = 'userinfo/' + user.id + '/'
|
|
if not os.path.exists(directory):
|
|
os.makedirs(directory)
|
|
with open(directory + 'calendarevents.json', 'w', encoding='utf-8') as f:
|
|
json.dump(calendarjson, f, ensure_ascii=False, indent=4)
|
|
'''
|
|
return calendarjson
|
|
|
|
|
|
def credentials_to_dict(credentials):
|
|
return{'token': credentials.token,
|
|
'refresh_token': credentials.refresh_token,
|
|
'token_uri': credentials.token_uri,
|
|
'client_id': credentials.client_id,
|
|
'client_secret': credentials.client_secret,
|
|
'scopes': credentials.scopes}
|
|
|
|
if __name__ == "__main__":
|
|
routine = Routine()
|
|
routine.start()
|