34 lines
903 B
Python
34 lines
903 B
Python
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()
|