adds more individualized calls from frontend

This commit is contained in:
Raphael Maenle 2020-04-15 17:15:13 +00:00
parent 8ad90fc8cc
commit fed3fddb21

View File

@ -9,8 +9,9 @@ from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request from google.auth.transport.requests import Request
# If modifying these scopes, delete the file token.pickle. # If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/calendar.readonly'] SCOPES = ["https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/calendar.readonly", "openid"]
API_SERVICE_NAME = 'calendar'
API_VERSION = 'v3'
visibleList = ['Hightower', 'Home', 'Office', 'Life', 'Social', 'Grey'] visibleList = ['Hightower', 'Home', 'Office', 'Life', 'Social', 'Grey']
class Event: class Event:
@ -173,7 +174,8 @@ def toNaturalColor(colormap, orgColor):
def colorizeEvents(allEvents, colors): def colorizeEvents(allEvents, colors):
with open("colors.json") as f: COLORS_FILE = os.path.join(os.path.dirname(__file__), 'colors.json')
with open(COLORS_FILE) as f:
colormap = json.load(f) colormap = json.load(f)
for event in allEvents: for event in allEvents:
@ -202,8 +204,7 @@ def toJson(events):
'stopDateTime': event.stopDateTime() 'stopDateTime': event.stopDateTime()
}) })
with open('./calendarevents.json', 'w') as outfile: return data
json.dump(data, outfile)
def printColors(colors): def printColors(colors):
for i in range(1, 25): for i in range(1, 25):
@ -213,9 +214,29 @@ def printColors(colors):
def main(): def main():
generateJsonFromCalendarEntries() generateJsonFromCalendarEntries()
def generateJsonFromCalendarEntries(token = None): def getCalendarList(credentials = None):
service = calendarCredentials(token) # create service
if credentials == None:
credentials = calendarCredentials()
service = build(API_SERVICE_NAME, API_VERSION, credentials=credentials)
calendars = getCalendars(service)
COLORS_FILE = os.path.join(os.path.dirname(__file__), 'colors.json')
with open(COLORS_FILE) as f:
colormap = json.load(f)
for calendar in calendars:
calendar.color = toNaturalColor(colormap, calendar.color)
return calendars
def generateJsonFromCalendarEntries(credentials = None):
# create service
if credentials == None:
credentials = calendarCredentials()
service = build(API_SERVICE_NAME, API_VERSION, credentials=credentials)
# define today and tomorrow # define today and tomorrow
now = datetime.datetime.now(datetime.timezone.utc).astimezone() now = datetime.datetime.now(datetime.timezone.utc).astimezone()
today = now.replace(hour=0, minute=0, second = 0).isoformat() today = now.replace(hour=0, minute=0, second = 0).isoformat()
@ -228,7 +249,7 @@ def generateJsonFromCalendarEntries(token = None):
# if not events: # if not events:
# print('No upcoming events found.') # print('No upcoming events found.')
toJson(allEvents) return toJson(allEvents)
if __name__ == '__main__': if __name__ == '__main__':
main() main()