adds more individualized calls from frontend
This commit is contained in:
parent
8ad90fc8cc
commit
fed3fddb21
37
caltojson.py
37
caltojson.py
@ -9,8 +9,9 @@ from google_auth_oauthlib.flow import InstalledAppFlow
|
||||
from google.auth.transport.requests import Request
|
||||
|
||||
# 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']
|
||||
|
||||
class Event:
|
||||
@ -173,7 +174,8 @@ def toNaturalColor(colormap, orgColor):
|
||||
|
||||
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)
|
||||
|
||||
for event in allEvents:
|
||||
@ -202,8 +204,7 @@ def toJson(events):
|
||||
'stopDateTime': event.stopDateTime()
|
||||
})
|
||||
|
||||
with open('./calendarevents.json', 'w') as outfile:
|
||||
json.dump(data, outfile)
|
||||
return data
|
||||
|
||||
def printColors(colors):
|
||||
for i in range(1, 25):
|
||||
@ -213,9 +214,29 @@ def printColors(colors):
|
||||
def main():
|
||||
generateJsonFromCalendarEntries()
|
||||
|
||||
def generateJsonFromCalendarEntries(token = None):
|
||||
service = calendarCredentials(token)
|
||||
def getCalendarList(credentials = None):
|
||||
# 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
|
||||
now = datetime.datetime.now(datetime.timezone.utc).astimezone()
|
||||
today = now.replace(hour=0, minute=0, second = 0).isoformat()
|
||||
@ -228,7 +249,7 @@ def generateJsonFromCalendarEntries(token = None):
|
||||
# if not events:
|
||||
# print('No upcoming events found.')
|
||||
|
||||
toJson(allEvents)
|
||||
return toJson(allEvents)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user