def get_notify_embeds(cal: GoogleCalendar, start: Arrow, end: Arrow) -> List[Tuple[Arrow, Embed]]: events_res = cal.get_events( time_min=start.datetime, time_max=end.datetime ) embeds = [] for event in events_res: embed = event2embed(event) if len(event.reminders) == 0: # One Notification at the time of the event pingTime = arrow.get(event.start) # if pingTime.is_between(start, end, '[)'): # yield (pingTime, embed,) # One notification 10 mins before pingTime = pingTime.shift(minutes=-10) if pingTime.is_between(start, end, '[)'): embeds.append((pingTime, embed,)) # There's currently a bug in gcsa # event.reminders is always empty # so this never gets triggered for r in event.reminders: if isinstance(r, PopupReminder): min_shift = -1*r.minutes_before_start pingTime = arrow.get(event.start).shift(minutes=min_shift) if pingTime.is_between(start, end, '[)'): embeds.append((pingTime, embed,)) return embeds
def get_embeds(cal: GoogleCalendar, start: Arrow, end: Arrow) -> List[Embed]: events_res = cal.get_events( time_min=start.datetime, time_max=end.datetime, order_by="startTime" ) events = list(map(lambda e: event2embed(event), events_res)) return events
def getEventsOneDate(date, calendarChoice): print("in model") bigRawEventTuple = [] bigRawAllDayEventTuple = [] bigRawNotAllDayEventTuple = [] print(calendarChoice) index = 0 for name in calendarChoice: index += 1 print(index) print(name) calendar = GoogleCalendar(name, creds) print(calendar) eventObjectArray = calendar.get_events(date, date, order_by='startTime') print(str(eventObjectArray)) print('' 'h') for event in eventObjectArray: print(str(event)) rawEvent = [] rawEvent.append(str(event.summary)) rawEvent.append(str(event.location)) print("in event") rawEvent.append(event.start.time()) rawEvent.append(event.end.time()) print(rawEvent) if len(str(event.start)) == 10: bigRawAllDayEventTuple.append(rawEvent) print("appending1") else: bigRawNotAllDayEventTuple.append(rawEvent) print("appending2") allDayEvents = sorted(bigRawAllDayEventTuple) notAllDayEvents = sorted(bigRawNotAllDayEventTuple, key=operator.itemgetter(1, 2)) bigRawEventTuple = allDayEvents + notAllDayEvents return (allDayEvents, notAllDayEvents)
df.index.max() # %% [markdown] # ## Read Events in Calendar which Are Within Timeframe of RGDB Data # # Add one day to timeframe to compensate for unpredictable time zone handling. # # Note IDs of existing events so we don't re-create them. # %% df['cal_id'] = None df['event_obj'] = None df['found'] = False for event in calendar.get_events( time_min=df.index.min() - datetime.timedelta(days=1), time_max=df.index.max() + datetime.timedelta(days=1), timezone='UTC'): df.loc[(df['Name'] == event.summary) & (df.index == event.start), ['found', 'cal_id', 'event_obj']] = [True, event.event_id, event] #if event.start in df.loc[df['Name'] == event.summary].index: # df.at[event.start, 'cal_id'] = event.event_id # df.at[event.start, 'event_obj'] = event # print('found ', event, event.timezone, event.event_id) # %% df.loc[df['found'] == False] # %% for index, row in df.iterrows():
try: cal = GoogleCalendar( calendar, credentials_path=XDG_CONFIG_HOME / "calcurse/credentials.json", read_only=True, ) except RefreshError: token = XDG_CONFIG_HOME / "calcurse/token.pickle" if token.exists(): token.unlink() print("Token expired. Re-auth manually...") sys.exit(1) for raw_event in cal.get_events(now, now + WINDOW, single_events=True, order_by="startTime"): event = CalEvent(calendar, raw_event) to_be_added[event._id] = event # Collect anything that *was* on the remote previously but is no longer for key in local_cache.events - set(to_be_added.keys()): to_be_removed.append(local_cache[key]) local_cache.remove(key) # Check all events that were previously added for key in local_cache.events & set(to_be_added.keys()): # check if the event was updated on the remote, if it is, remove the # old and re-add the updated event if local_cache[key].fingerprint != to_be_added[key].fingerprint: to_be_removed.append(local_cache[key])
class TestGoogleCalendarAPI(TestCase): def setUp(self): self.build_patcher = patch('googleapiclient.discovery.build', return_value=MockService()) self.build_patcher.start() self.gc = GoogleCalendar(credentials=MockToken(valid=True)) def tearDown(self): self.build_patcher.stop() def test_get_events_default(self): events = list(self.gc.get_events()) self.assertEqual(len(events), 10) self.assertFalse(any(e.is_recurring_instance for e in events)) events = list(self.gc) self.assertEqual(len(events), 10) self.assertFalse(any(e.is_recurring_instance for e in events)) def test_get_events_time_limits(self): time_min = insure_localisation(D.today()[:] + 5 * days) events = list(self.gc.get_events(time_min=time_min)) self.assertEqual(len(events), 6) self.assertTrue(all(e.start >= time_min for e in events)) time_min = insure_localisation(D.today()[:] + 5 * days) events = list(self.gc[time_min]) self.assertEqual(len(events), 6) self.assertTrue(all(e.start >= time_min for e in events)) time_max = insure_localisation(D.today()[:] + 1 * years + 7 * days) events = list(self.gc.get_events(time_max=time_max)) self.assertEqual(len(events), 11) self.assertTrue(all(e.end < time_max for e in events)) time_max = insure_localisation(D.today()[:] + 7 * days) events = list(self.gc.get_events(time_max=time_max)) self.assertEqual(len(events), 7) self.assertTrue(all(e.end < time_max for e in events)) events = list(self.gc.get_events(time_min=time_min, time_max=time_max)) self.assertEqual(len(events), 2) self.assertTrue( all(time_min <= e.start and e.end < time_max for e in events)) events = list(self.gc[time_min:time_max]) self.assertEqual(len(events), 2) self.assertTrue( all(time_min <= e.start and e.end < time_max for e in events)) time_min = D.today() + 5 * days time_max = D.today() + 7 * days events = list(self.gc.get_events(time_min=time_min, time_max=time_max)) self.assertEqual(len(events), 3) time_min = insure_localisation(time_min[0:0]) time_max = insure_localisation(time_max[23:59:59]) self.assertTrue( all(time_min <= e.start and e.end < time_max for e in events)) with self.assertRaises(NotImplementedError): _ = self.gc[5] with self.assertRaises(ValueError): _ = self.gc[5:10] def test_get_events_single_events(self): events = list(self.gc.get_events(single_events=True)) self.assertEqual(len(events), 19) self.assertTrue( all(e.is_recurring_instance for e in events if e.summary == 'Recurring event')) events = list(self.gc.get_events(single_events=False)) self.assertEqual(len(events), 10) self.assertTrue( all(not e.is_recurring_instance for e in events if e.summary == 'Recurring event')) with self.assertRaises(ValueError): # can only be used with single events list(self.gc.get_events(order_by='startTime')) def test_get_events_order_by(self): events = list(self.gc.get_events(order_by='updated')) self.assertEqual(len(events), 10) self.assertEqual(events[0].id, min(events, key=lambda e: e.updated).id) self.assertEqual(events[-1].id, max(events, key=lambda e: e.updated).id) events = list(self.gc[::'updated']) self.assertEqual(len(events), 10) self.assertEqual(events[0].id, min(events, key=lambda e: e.updated).id) self.assertEqual(events[-1].id, max(events, key=lambda e: e.updated).id) events = list(self.gc[::'startTime']) self.assertEqual(len(events), 19) self.assertEqual(events[0].id, min(events, key=lambda e: e.start).id) self.assertEqual(events[-1].id, max(events, key=lambda e: e.start).id) events = list( self.gc.get_events(order_by='startTime', single_events=True)) self.assertEqual(len(events), 19) self.assertEqual(events[0].id, min(events, key=lambda e: e.start).id) self.assertEqual(events[-1].id, max(events, key=lambda e: e.start).id) def test_get_events_query(self): events = list( self.gc.get_events(query='test4', time_max=D.today()[:] + 2 * years)) self.assertEqual(len(events), 2) # test4 and test42 events = list( self.gc.get_events(query='Jo', time_max=D.today()[:] + 2 * years)) self.assertEqual(len(events), 2) # with John and Josh events = list( self.gc.get_events(query='Josh', time_max=D.today()[:] + 2 * years)) self.assertEqual(len(events), 1) events = list( self.gc.get_events(query='Frank', time_max=D.today()[:] + 2 * years)) self.assertEqual(len(events), 1) def test_get_recurring_instances(self): events = list(self.gc.get_instances(recurring_event='event_id_1')) self.assertEqual(len(events), 9) self.assertTrue(all(e.id.startswith('event_id_1') for e in events)) recurring_event = Event('recurring event', D.today()[:], event_id='event_id_2') events = list(self.gc.get_instances(recurring_event=recurring_event)) self.assertEqual(len(events), 4) self.assertTrue(all(e.id.startswith('event_id_2') for e in events))