def test_to_json_attendees(self): e = Event('Good day', start=(1 / Jul / 2020)[11:22:33], timezone=TEST_TIMEZONE, attendees=[ Attendee(email='*****@*****.**', response_status=ResponseStatus.NEEDS_ACTION), Attendee(email='*****@*****.**', response_status=ResponseStatus.ACCEPTED), ]) event_json = { 'summary': 'Good day', 'start': { 'dateTime': '2020-07-01T11:22:33+12:00', 'timeZone': TEST_TIMEZONE }, 'end': { 'dateTime': '2020-07-01T12:22:33+12:00', 'timeZone': TEST_TIMEZONE }, 'recurrence': [], 'visibility': 'default', 'attendees': [ { 'email': '*****@*****.**', 'responseStatus': ResponseStatus.NEEDS_ACTION }, { 'email': '*****@*****.**', 'responseStatus': ResponseStatus.ACCEPTED }, ], 'reminders': { 'useDefault': False }, 'attachments': [] } self.assertDictEqual(EventSerializer.to_json(e), event_json) e = Event('Good day2', start=20 / Jul / 2020, default_reminders=True) event_json = { 'summary': 'Good day2', 'start': { 'date': '2020-07-20' }, 'end': { 'date': '2020-07-21' }, 'recurrence': [], 'visibility': 'default', 'attendees': [], 'reminders': { 'useDefault': True }, 'attachments': [] } self.assertDictEqual(EventSerializer.to_json(e), event_json)
def test_to_json(self): e = Event('Good day', start=(28 / Sept / 2019), timezone=TEST_TIMEZONE) expected_event_json = { 'summary': 'Good day', 'start': { 'date': '2019-09-28' }, 'end': { 'date': '2019-09-29' }, 'recurrence': [], 'visibility': 'default', 'attendees': [], 'reminders': { 'useDefault': False }, 'attachments': [], 'guestsCanInviteOthers': True, 'guestsCanModify': False, 'guestsCanSeeOtherGuests': True, } self.assertDictEqual(EventSerializer.to_json(e), expected_event_json) e = Event('Good day', start=(28 / Oct / 2019)[11:22:33], timezone=TEST_TIMEZONE) expected_event_json = { 'summary': 'Good day', 'start': { 'dateTime': '2019-10-28T11:22:33+12:00', 'timeZone': TEST_TIMEZONE }, 'end': { 'dateTime': '2019-10-28T12:22:33+12:00', 'timeZone': TEST_TIMEZONE }, 'recurrence': [], 'visibility': 'default', 'attendees': [], 'reminders': { 'useDefault': False }, 'attachments': [], 'guestsCanInviteOthers': True, 'guestsCanModify': False, 'guestsCanSeeOtherGuests': True, } self.assertDictEqual(EventSerializer.to_json(e), expected_event_json)
def test_to_json_reminders(self): e = Event('Good day', start=(1 / Jan / 2019)[11:22:33], timezone=TEST_TIMEZONE, minutes_before_popup_reminder=30, minutes_before_email_reminder=120) event_json = { 'summary': 'Good day', 'start': { 'dateTime': '2019-01-01T11:22:33+13:00', 'timeZone': TEST_TIMEZONE }, 'end': { 'dateTime': '2019-01-01T12:22:33+13:00', 'timeZone': TEST_TIMEZONE }, 'recurrence': [], 'visibility': 'default', 'attendees': [], 'reminders': { 'overrides': [{ 'method': 'popup', 'minutes': 30 }, { 'method': 'email', 'minutes': 120 }], 'useDefault': False }, 'attachments': [] } self.assertDictEqual(EventSerializer.to_json(e), event_json)
def query_events(calendar, end, start=MIN_DATE, drop_invalid=True): """Get events from one calendar""" data = [] # Retrive all events between start and end events = calendar.get_events(start, end, order_by="updated", single_events=True) for event in events: data.append({ # Serialize the event **EventSerializer.to_json(event), # And replace 'start' and 'end' with the easier to use values # Defaults from 'to_json' are dict that include timezone and we don't want that "start": event.start, "end": event.end, }) # Return them as a nice pandas dataframe df = pd.DataFrame(data) if drop_invalid: df = df.dropna(subset=["start"]) return df
def test_to_json_attachments(self): e = Event('Good day', start=(1 / Jan / 2019)[11:22:33], timezone=TEST_TIMEZONE, attachments=[ Attachment('My file1', 'https://file.url1', "application/vnd.google-apps.document"), Attachment('My file2', 'https://file.url2', "application/vnd.google-apps.document") ]) event_json = { 'summary': 'Good day', 'start': {'dateTime': '2019-01-01T11:22:33+13:00', 'timeZone': TEST_TIMEZONE}, 'end': {'dateTime': '2019-01-01T12:22:33+13:00', 'timeZone': TEST_TIMEZONE}, 'recurrence': [], 'visibility': 'default', 'reminders': {'useDefault': False}, 'attachments': [ { 'title': 'My file1', 'fileUrl': 'https://file.url1', 'mimeType': 'application/vnd.google-apps.document' }, { 'title': 'My file2', 'fileUrl': 'https://file.url2', 'mimeType': 'application/vnd.google-apps.document' } ] } self.assertDictEqual(EventSerializer.to_json(e), event_json)
def test_to_json_recurrence(self): e = Event('Good day', start=(1 / Jan / 2019)[11:22:33], end=(1 / Jan / 2020)[11:22:33], timezone=TEST_TIMEZONE, recurrence=[ Recurrence.rule(freq=DAILY), Recurrence.exclude_rule(by_week_day=MONDAY), Recurrence.exclude_dates([ 19 / Apr / 2019, 22 / Apr / 2019, 12 / May / 2019 ]) ]) event_json = { 'summary': 'Good day', 'start': {'dateTime': '2019-01-01T11:22:33+13:00', 'timeZone': TEST_TIMEZONE}, 'end': {'dateTime': '2020-01-01T11:22:33+13:00', 'timeZone': TEST_TIMEZONE}, 'recurrence': [ 'RRULE:FREQ=DAILY;WKST=SU', 'EXRULE:FREQ=DAILY;BYDAY=MO;WKST=SU', 'EXDATE;VALUE=DATE:20190419,20190422,20190512' ], 'visibility': 'default', 'reminders': {'useDefault': False}, 'attachments': [] } self.assertDictEqual(EventSerializer.to_json(e), event_json)
def test_to_json_updated(self): e = Event('Good day', start=(1 / Jul / 2020)[11:22:33], timezone=TEST_TIMEZONE, _updated=insure_localisation((25 / Nov / 2020)[11:22:33], timezone=TEST_TIMEZONE)) expected_event_json = { 'summary': 'Good day', 'start': { 'dateTime': '2020-07-01T11:22:33+12:00', 'timeZone': TEST_TIMEZONE }, 'end': { 'dateTime': '2020-07-01T12:22:33+12:00', 'timeZone': TEST_TIMEZONE }, 'recurrence': [], 'visibility': 'default', 'attendees': [], 'reminders': { 'useDefault': False }, 'attachments': [], 'guestsCanInviteOthers': True, 'guestsCanModify': False, 'guestsCanSeeOtherGuests': True, } self.assertDictEqual(EventSerializer.to_json(e), expected_event_json)
def test_to_json_conference_solution(self): e = Event('Good day', start=(1 / Jul / 2020)[11:22:33], timezone=TEST_TIMEZONE, conference_solution=ConferenceSolution( entry_points=EntryPoint(EntryPoint.VIDEO, uri='https://video.com'), solution_type=SolutionType.HANGOUTS_MEET, name='Hangout', icon_uri='https://icon.com', conference_id='aaa-bbbb-ccc', signature='abc4efg12345', notes='important notes')) expected_event_json = { 'summary': 'Good day', 'start': { 'dateTime': '2020-07-01T11:22:33+12:00', 'timeZone': TEST_TIMEZONE }, 'end': { 'dateTime': '2020-07-01T12:22:33+12:00', 'timeZone': TEST_TIMEZONE }, 'recurrence': [], 'visibility': 'default', 'attendees': [], 'reminders': { 'useDefault': False }, 'attachments': [], 'conferenceData': { 'entryPoints': [{ 'entryPointType': 'video', 'uri': 'https://video.com', }], 'conferenceSolution': { 'key': { 'type': 'hangoutsMeet' }, 'name': 'Hangout', 'iconUri': 'https://icon.com' }, 'conferenceId': 'aaa-bbbb-ccc', 'signature': 'abc4efg12345', 'notes': 'important notes' }, 'guestsCanInviteOthers': True, 'guestsCanModify': False, 'guestsCanSeeOtherGuests': True, } self.assertDictEqual(EventSerializer.to_json(e), expected_event_json)
def test_to_json_conference_solution_create_request(self): e = Event('Good day', start=(1 / Jul / 2020)[11:22:33], timezone=TEST_TIMEZONE, conference_solution=ConferenceSolutionCreateRequest( solution_type=SolutionType.HANGOUTS_MEET, request_id='hello1234', conference_id='conference-id', signature='signature', notes='important notes', _status='pending')) expected_event_json = { 'summary': 'Good day', 'start': { 'dateTime': '2020-07-01T11:22:33+12:00', 'timeZone': TEST_TIMEZONE }, 'end': { 'dateTime': '2020-07-01T12:22:33+12:00', 'timeZone': TEST_TIMEZONE }, 'recurrence': [], 'visibility': 'default', 'attendees': [], 'reminders': { 'useDefault': False }, 'attachments': [], 'conferenceData': { 'createRequest': { 'requestId': 'hello1234', 'conferenceSolutionKey': { 'type': 'hangoutsMeet' }, 'status': { 'statusCode': 'pending' } }, 'conferenceId': 'conference-id', 'signature': 'signature', 'notes': 'important notes' }, 'guestsCanInviteOthers': True, 'guestsCanModify': False, 'guestsCanSeeOtherGuests': True, } self.assertDictEqual(EventSerializer.to_json(e), expected_event_json)
async def update_event(self): await self.bot.wait_until_ready() notify_channel = self.bot.get_channel(None) def get_new_notify_msg(): pass for event in self.gc: event_data = self.gc_cursor.find_one({"_id": event.id}) if not event_data: continue event_obj = dict(EventSerializer.to_json(event)) # etag has been modified => event has been modified if event_obj["etag"] != event_data["etag"]: # renew all info of event event_start_time = pend.parse(str(event.start), tz='Asia/Taipei') event_end_time = pend.parse(str(event.end), tz='Asia/Taipei') execute = { "$set": { "etag": event_obj["etag"], "summary": event.summary, "location": event.location, "start": event_start_time, "end": event_end_time } } self.gc_cursor.update_one({"_id": event.id}, execute) # repost notify old_notify_dc_msg = notify_channel.fetch_message(event_data["msg_id"]) await old_notify_dc_msg.delete() notify_msg = get_new_notify_msg() notify_dc_msg = await notify_channel.send(notify_msg) execute = { "$set": { "msg_id": notify_dc_msg.id } } self.gc_cursor.update_one({"_id": event.id}, execute)
async def collect_event(self): await self.bot.wait_until_ready() for event in self.gc: event_data = self.gc_cursor.find_one({"_id": event.id}) if event_data: continue event_obj = dict(EventSerializer.to_json(event)) event_start_time = pend.parse(str(event.start), tz='Asia/Taipei').to_datetime_string() event_end_time = pend.parse(str(event.end), tz='Asia/Taipei').to_datetime_string() event_data = { "_id": event.id, "etag": event_obj["etag"], "summary": event.summary, "location": event.location, "start": event_start_time, "end": event_end_time, "msg_id": None, "notify_stage": None } self.gc_cursor.insert_one(event_data)
def _serialize_event(e): event_json = EventSerializer.to_json(e) event_json['updated'] = e.updated.isoformat() + 'Z' return event_json