changes process the colors are remapped into a more capsuled function
This commit is contained in:
		
							
								
								
									
										30
									
								
								caltojson.py
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								caltojson.py
									
									
									
									
									
								
							| @@ -172,20 +172,25 @@ def toNaturalColor(colormap, orgColor): | |||||||
|     print(f"failed with {orgColor}") |     print(f"failed with {orgColor}") | ||||||
|     return orgColor |     return orgColor | ||||||
|  |  | ||||||
| def colorizeEvents(allEvents, colors): | def colorizeEvents(allEvents, service): | ||||||
|  |  | ||||||
|     COLORS_FILE = os.path.join(os.path.dirname(__file__), 'colors.json') |     COLORS_FILE = os.path.join(os.path.dirname(__file__), 'colors.json') | ||||||
|     with open(COLORS_FILE) as f: |     with open(COLORS_FILE) as f: | ||||||
|         colormap = json.load(f) |         colormap = json.load(f) | ||||||
|          |          | ||||||
|     for event in allEvents: |     colors = getCalendarColors(service) | ||||||
|         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) |     for event in allEvents: | ||||||
|  |         event.colorHex = fromColorIdGetColor(event.calendarColorId, colormap, colors) | ||||||
|  |  | ||||||
|  | def fromColorIdGetColor(colorId, colormap, colors): | ||||||
|  |  | ||||||
|  |     if colorId != 0: | ||||||
|  |         orgColor = colors['calendar'][colorId]['background'] | ||||||
|  |     else: | ||||||
|  |         calColorId = toCalendarColorId(colormap, colorId) | ||||||
|  |         orgColor = colors['calendar'][calColorId]['background'] | ||||||
|  |      | ||||||
|  |     return toNaturalColor(colormap, orgColor) | ||||||
|  |  | ||||||
| def toJson(events): | def toJson(events): | ||||||
|     data = {} |     data = {} | ||||||
| @@ -226,8 +231,10 @@ def getCalendarList(credentials = None): | |||||||
|     with open(COLORS_FILE) as f: |     with open(COLORS_FILE) as f: | ||||||
|         colormap = json.load(f) |         colormap = json.load(f) | ||||||
|          |          | ||||||
|  |     colors = getCalendarColors(service) | ||||||
|  |  | ||||||
|     for calendar in calendars: |     for calendar in calendars: | ||||||
|         calendar.color = toNaturalColor(colormap, calendar.color) |         calendar.color = fromColorIdGetColor(calendar.color, colormap, colors) | ||||||
|     return calendars |     return calendars | ||||||
|  |  | ||||||
| def generateJsonFromCalendarEntries(credentials = None): | def generateJsonFromCalendarEntries(credentials = None): | ||||||
| @@ -244,8 +251,7 @@ def generateJsonFromCalendarEntries(credentials = None): | |||||||
|      |      | ||||||
|     allEvents = getCalendarEvents(service, today, tomorrow) |     allEvents = getCalendarEvents(service, today, tomorrow) | ||||||
|  |  | ||||||
|     colors = getCalendarColors(service) |     colorizeEvents(allEvents, service) | ||||||
|     colorizeEvents(allEvents, colors) |  | ||||||
|     # if not events: |     # if not events: | ||||||
|     #    print('No upcoming events found.') |     #    print('No upcoming events found.') | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user