Compare commits
	
		
			1 Commits
		
	
	
		
			87a229f791
			...
			183bf60fc0
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 183bf60fc0 | 
							
								
								
									
										60
									
								
								__init__.py
									
									
									
									
									
								
							
							
						
						
									
										60
									
								
								__init__.py
									
									
									
									
									
								
							@@ -8,6 +8,7 @@ from google_auth_oauthlib.flow import InstalledAppFlow
 | 
				
			|||||||
from google.auth.transport.requests import Request
 | 
					from google.auth.transport.requests import Request
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from server import db
 | 
					from server import db
 | 
				
			||||||
 | 
					from database.models import Calendar as dbCalendar
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# If modifying these scopes, delete the file token.pickle.
 | 
					# If modifying these scopes, delete the file token.pickle.
 | 
				
			||||||
SCOPES = ["https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/calendar.readonly", "openid"]
 | 
					SCOPES = ["https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/calendar.readonly", "openid"]
 | 
				
			||||||
@@ -24,9 +25,7 @@ class Calendar:
 | 
				
			|||||||
class Event:
 | 
					class Event:
 | 
				
			||||||
    def __init__(self, name_, start_, end_):
 | 
					    def __init__(self, name_, start_, end_):
 | 
				
			||||||
        self.name = name_
 | 
					        self.name = name_
 | 
				
			||||||
        self.eventColorId = 0
 | 
					        self.eventColorId = None
 | 
				
			||||||
        self.calendarColorId = None 
 | 
					 | 
				
			||||||
        self.naturalColorId = 0
 | 
					 | 
				
			||||||
        self.start = start_
 | 
					        self.start = start_
 | 
				
			||||||
        self.end = end_
 | 
					        self.end = end_
 | 
				
			||||||
        self.colorHex = '#adfff5'
 | 
					        self.colorHex = '#adfff5'
 | 
				
			||||||
@@ -65,9 +64,6 @@ class Event:
 | 
				
			|||||||
    def print(self):
 | 
					    def print(self):
 | 
				
			||||||
        if self.allDay:
 | 
					        if self.allDay:
 | 
				
			||||||
            print(self.name + "All Day")
 | 
					            print(self.name + "All Day")
 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            print(self.name + ": " + self.naturalColorId)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def calendarCredentials(token = None):
 | 
					def calendarCredentials(token = None):
 | 
				
			||||||
@@ -114,11 +110,11 @@ def updateCalendars(user, calendars, colors):
 | 
				
			|||||||
        if not user.hasCalendar(calendar.calendarId):
 | 
					        if not user.hasCalendar(calendar.calendarId):
 | 
				
			||||||
            color = fromColorIdGetColor(calendar.color, colormap, colors)
 | 
					            color = fromColorIdGetColor(calendar.color, colormap, colors)
 | 
				
			||||||
            c = dbCalendar(calendar_id=calendar.calendarId, 
 | 
					            c = dbCalendar(calendar_id=calendar.calendarId, 
 | 
				
			||||||
                           name = calendar.summary,
 | 
					                           name = calendar.name,
 | 
				
			||||||
                           toggle = "False",
 | 
					                           toggle = "False",
 | 
				
			||||||
                           color = color)
 | 
					                           color = color)
 | 
				
			||||||
            db.session.add(c)
 | 
					            db.session.add(c)
 | 
				
			||||||
            current_user.calendars.append(c)
 | 
					            user.calendars.append(c)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    db.session.commit()
 | 
					    db.session.commit()
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@@ -142,47 +138,6 @@ def purgeCalendars(calendars, visibleCalendars):
 | 
				
			|||||||
            purged.append(calendar)
 | 
					            purged.append(calendar)
 | 
				
			||||||
    return purged
 | 
					    return purged
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def getCalendarEvents(service, userCalendars, startDate, endDate):
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    visualCals = []
 | 
					 | 
				
			||||||
    for calendar in userCalendars:
 | 
					 | 
				
			||||||
        if calendar.toggle == 'True':
 | 
					 | 
				
			||||||
            visualCals.append(calendar.calendar_id)
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    calendars = getCalendars(service)
 | 
					 | 
				
			||||||
    calendars = purgeCalendars(calendars, visualCals)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    all_events = []
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for calendar in calendars:
 | 
					 | 
				
			||||||
        events_result = service.events().list(calendarId=calendar.calendarId, timeMin=startDate,
 | 
					 | 
				
			||||||
                                            timeMax=endDate,
 | 
					 | 
				
			||||||
                                            maxResults=10, singleEvents=True,
 | 
					 | 
				
			||||||
                                            orderBy='startTime').execute()
 | 
					 | 
				
			||||||
        for event in events_result.get('items', []):
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            # create simple event
 | 
					 | 
				
			||||||
            name = event.get('summary', '(no Title)')
 | 
					 | 
				
			||||||
            start = event['start'].get('dateTime')
 | 
					 | 
				
			||||||
            end = event['end'].get('dateTime')
 | 
					 | 
				
			||||||
            newEvent = Event(name, start, end)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            # handle weird colors from google
 | 
					 | 
				
			||||||
            color = event.get('colorId')
 | 
					 | 
				
			||||||
            if color == None:
 | 
					 | 
				
			||||||
                for userCalendar in userCalendars:
 | 
					 | 
				
			||||||
                    if userCalendar.calendar_id == calendar.calendarId:
 | 
					 | 
				
			||||||
                        newEvent.calendarHex = userCalendar.color
 | 
					 | 
				
			||||||
                newEvent.calendarColorId = calendar.color
 | 
					 | 
				
			||||||
            else:
 | 
					 | 
				
			||||||
                newEvent.eventColorId = color
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            all_events.append(newEvent)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return all_events
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
def toCalendarColorId(colormap, colorId):
 | 
					def toCalendarColorId(colormap, colorId):
 | 
				
			||||||
    for remap in colormap['eventRemap']:
 | 
					    for remap in colormap['eventRemap']:
 | 
				
			||||||
@@ -205,9 +160,9 @@ def colorizeEvents(events, colors):
 | 
				
			|||||||
    with open(COLORS_FILE) as f:
 | 
					    with open(COLORS_FILE) as f:
 | 
				
			||||||
        colormap = json.load(f)
 | 
					        colormap = json.load(f)
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    for event in events:
 | 
					    for event in events:
 | 
				
			||||||
        if event.calendarColorId != None:
 | 
					        print(event.colorHex, flush=True) 
 | 
				
			||||||
 | 
					        if event.eventColorId != None:
 | 
				
			||||||
            event.colorHex = forEventGetColor(event, colormap, colors)
 | 
					            event.colorHex = forEventGetColor(event, colormap, colors)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# this function is only used once for calendar generation stuff
 | 
					# this function is only used once for calendar generation stuff
 | 
				
			||||||
@@ -215,9 +170,6 @@ def fromColorIdGetColor(color, colormap, colors):
 | 
				
			|||||||
    return toNaturalColor(colormap, colors['calendar'][color]['background'])
 | 
					    return toNaturalColor(colormap, colors['calendar'][color]['background'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def forEventGetColor(event, colormap, colors):
 | 
					def forEventGetColor(event, colormap, colors):
 | 
				
			||||||
    if event.calendarColorId != 0:
 | 
					 | 
				
			||||||
        bg  = colors['calendar'][event.calendarColorId]['background']
 | 
					 | 
				
			||||||
    else:
 | 
					 | 
				
			||||||
    calColorId = toCalendarColorId(colormap, event.eventColorId)
 | 
					    calColorId = toCalendarColorId(colormap, event.eventColorId)
 | 
				
			||||||
    bg = colors['calendar'][calColorId]['background']     
 | 
					    bg = colors['calendar'][calColorId]['background']     
 | 
				
			||||||
    return toNaturalColor(colormap, bg)
 | 
					    return toNaturalColor(colormap, bg)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user