created color correction using a .json file and remapping the colors from the api to the colors actually shown in the google calendar online visualization
This commit is contained in:
parent
1bd2dcd460
commit
5a0d715929
146
colors.json
Normal file
146
colors.json
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
{
|
||||||
|
"colors": [
|
||||||
|
{
|
||||||
|
"api": "#ac725e",
|
||||||
|
"natural": "#795548"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#d06b64",
|
||||||
|
"natural": "#9331C4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#f83a22",
|
||||||
|
"natural": "#8E24AA"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#fa573c",
|
||||||
|
"natural": "#E67C73"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#ff7537",
|
||||||
|
"natural": "#EF6C00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#ffad46",
|
||||||
|
"natural": "#F09300"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#42d692",
|
||||||
|
"natural": "#009688"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#16a765",
|
||||||
|
"natural": "#0B8043"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#7bd148",
|
||||||
|
"natural": "#7CB342"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#b3dc6c",
|
||||||
|
"natural": "#C0CA33"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#fbe983",
|
||||||
|
"natural": "#E4C441"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#fad165",
|
||||||
|
"natural": "#F6BF26"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#92e1c0",
|
||||||
|
"natural": "#33B679"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#9fe1e7",
|
||||||
|
"natural": "#039BE5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#9fc6e7",
|
||||||
|
"natural": "#4285F4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#4986e7",
|
||||||
|
"natural": "#3F51B5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#9a9cff",
|
||||||
|
"natural": "#7986CB"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#b99aff",
|
||||||
|
"natural": "#B39DDB"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#c2c2c2",
|
||||||
|
"natural": "#616161"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#cabdbf",
|
||||||
|
"natural": "#A79B8E"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#cca6ac",
|
||||||
|
"natural": "#AD1457"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#f691b2",
|
||||||
|
"natural": "#D81B60"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#cd74e6",
|
||||||
|
"natural": "#8E24AA"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"api": "#a47ae2",
|
||||||
|
"natural": "#9E69AF"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"eventRemap": [
|
||||||
|
{
|
||||||
|
"from": "11",
|
||||||
|
"to": "3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": "4",
|
||||||
|
"to": "2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": "6",
|
||||||
|
"to": "4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": "5",
|
||||||
|
"to": "12"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": "7",
|
||||||
|
"to": "14"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": "9",
|
||||||
|
"to": "16"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": "1",
|
||||||
|
"to": "17"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": "3",
|
||||||
|
"to": "23"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": "8",
|
||||||
|
"to": "19"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": "2",
|
||||||
|
"to": "18"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": "10",
|
||||||
|
"to": "8"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -11,12 +11,14 @@ 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/calendar.readonly']
|
||||||
|
|
||||||
visibleList = ['Hightower', 'Home \ud83c\udfe0', 'Office', 'Life', 'Social', 'Grey']
|
visibleList = ['Hightower', 'Home', 'Office', 'Life', 'Social', 'Grey']
|
||||||
|
|
||||||
class Event:
|
class Event:
|
||||||
def __init__(self, name_, colorId_, start_, end_):
|
def __init__(self, name_, start_, end_):
|
||||||
self.name = name_
|
self.name = name_
|
||||||
self.colorId = colorId_
|
self.eventColorId = 0
|
||||||
|
self.calendarColorId = 0
|
||||||
|
self.naturalColorId = 0
|
||||||
self.start = start_
|
self.start = start_
|
||||||
self.end = end_
|
self.end = end_
|
||||||
self.colorHex = '#adfff5'
|
self.colorHex = '#adfff5'
|
||||||
@ -56,7 +58,7 @@ class Event:
|
|||||||
if self.allDay:
|
if self.allDay:
|
||||||
print(self.name + "All Day")
|
print(self.name + "All Day")
|
||||||
else:
|
else:
|
||||||
print(self.name + ": " + self.start + ", " + self.end)
|
print(self.name + ": " + self.NaturalColorId)
|
||||||
|
|
||||||
|
|
||||||
class Calendar:
|
class Calendar:
|
||||||
@ -109,7 +111,6 @@ def getCalendars(service):
|
|||||||
def purgeCalendars(calendars):
|
def purgeCalendars(calendars):
|
||||||
purged = []
|
purged = []
|
||||||
for calendar in calendars:
|
for calendar in calendars:
|
||||||
print(calendar.summary)
|
|
||||||
if calendar.summary in visibleList:
|
if calendar.summary in visibleList:
|
||||||
purged.append(calendar)
|
purged.append(calendar)
|
||||||
return purged
|
return purged
|
||||||
@ -129,22 +130,54 @@ def getCalendarEvents(service, startDate, endDate):
|
|||||||
|
|
||||||
for event in events_result.get('items', []):
|
for event in events_result.get('items', []):
|
||||||
|
|
||||||
|
# create simple event
|
||||||
name = event['summary']
|
name = event['summary']
|
||||||
start = event['start'].get('dateTime')
|
start = event['start'].get('dateTime')
|
||||||
end = event['end'].get('dateTime')
|
end = event['end'].get('dateTime')
|
||||||
|
newEvent = Event(name, start, end)
|
||||||
|
|
||||||
|
# handle weird colors from google
|
||||||
color = event.get('colorId')
|
color = event.get('colorId')
|
||||||
if color == None:
|
if color == None:
|
||||||
color = calendar.color
|
newEvent.calendarColorId = calendar.color
|
||||||
|
else:
|
||||||
|
newEvent.eventColorId = color
|
||||||
|
|
||||||
event = Event(name, color, start, end)
|
|
||||||
all_events.append(event)
|
all_events.append(newEvent)
|
||||||
|
|
||||||
return all_events
|
return all_events
|
||||||
|
|
||||||
|
def toCalendarColorId(colormap, colorId):
|
||||||
|
for remap in colormap['eventRemap']:
|
||||||
|
if remap['from'] == colorId:
|
||||||
|
return remap['to']
|
||||||
|
|
||||||
|
print(f"failed with {colorId}")
|
||||||
|
return colorId
|
||||||
|
|
||||||
|
def toNaturalColor(colormap, orgColor):
|
||||||
|
for remap in colormap['colors']:
|
||||||
|
if remap['api'] == orgColor:
|
||||||
|
return remap['natural']
|
||||||
|
|
||||||
|
print(f"failed with {orgColor}")
|
||||||
|
return orgColor
|
||||||
|
|
||||||
def colorizeEvents(allEvents, colors):
|
def colorizeEvents(allEvents, colors):
|
||||||
|
|
||||||
|
with open("colors.json") as f:
|
||||||
|
colormap = json.load(f)
|
||||||
|
|
||||||
for event in allEvents:
|
for event in allEvents:
|
||||||
event.colorHex = colors['calendar'][event.colorId]['background']
|
if event.calendarColorId != 0:
|
||||||
|
orgColor = colors['calendar'][event.calendarColorId]['background']
|
||||||
|
else:
|
||||||
|
calColorId = toCalendarColorId(colormap, event.eventColorId)
|
||||||
|
orgColor = colors['calendar'][calColorId]['background']
|
||||||
|
|
||||||
|
event.colorHex = toNaturalColor(colormap, orgColor)
|
||||||
|
|
||||||
def toJson(events):
|
def toJson(events):
|
||||||
data = {}
|
data = {}
|
||||||
data['kind'] = 'calendar#events'
|
data['kind'] = 'calendar#events'
|
||||||
@ -153,6 +186,7 @@ def toJson(events):
|
|||||||
for event in events:
|
for event in events:
|
||||||
if event.allDay:
|
if event.allDay:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
data['events'].append({
|
data['events'].append({
|
||||||
'name': event.name,
|
'name': event.name,
|
||||||
'isAllDay': event.allDay,
|
'isAllDay': event.allDay,
|
||||||
@ -164,6 +198,10 @@ def toJson(events):
|
|||||||
with open('./calendarevents.json', 'w') as outfile:
|
with open('./calendarevents.json', 'w') as outfile:
|
||||||
json.dump(data, outfile)
|
json.dump(data, outfile)
|
||||||
|
|
||||||
|
def printColors(colors):
|
||||||
|
for i in range(1, 25):
|
||||||
|
col = colors['event'][str(i)]['background']
|
||||||
|
print(f"{i}: {col}")
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
service = calendarCredentials()
|
service = calendarCredentials()
|
||||||
|
BIN
token.pickle
BIN
token.pickle
Binary file not shown.
Loading…
Reference in New Issue
Block a user