def test_ewsdatetime(self): tz = EWSTimeZone.timezone('Europe/Copenhagen') self.assertIsInstance(tz, EWSTimeZone) self.assertEqual(tz.ms_id, 'Romance Standard Time') self.assertEqual(tz.ms_name, '(UTC+01:00) Brussels, Copenhagen, Madrid, Paris') dt = tz.localize(EWSDateTime(2000, 1, 2, 3, 4, 5)) self.assertIsInstance(dt, EWSDateTime) self.assertIsInstance(dt.tzinfo, EWSTimeZone) self.assertEqual(dt.tzinfo.ms_id, tz.ms_id) self.assertEqual(dt.tzinfo.ms_name, tz.ms_name) self.assertEqual(str(dt), '2000-01-02 03:04:05+01:00') self.assertEqual( repr(dt), "EWSDateTime(2000, 1, 2, 3, 4, 5, tzinfo=<DstTzInfo 'Europe/Copenhagen' CET+1:00:00 STD>)" ) self.assertIsInstance(dt + timedelta(days=1), EWSDateTime) self.assertIsInstance(dt - timedelta(days=1), EWSDateTime) self.assertIsInstance(dt - EWSDateTime.now(tz=tz), timedelta) self.assertIsInstance(EWSDateTime.now(tz=tz), EWSDateTime) self.assertEqual(dt, EWSDateTime.from_datetime(tz.localize(datetime(2000, 1, 2, 3, 4, 5)))) self.assertEqual(dt.ewsformat(), '2000-01-02T03:04:05') utc_tz = EWSTimeZone.timezone('UTC') self.assertEqual(dt.astimezone(utc_tz).ewsformat(), '2000-01-02T02:04:05Z') # Test summertime dt = tz.localize(EWSDateTime(2000, 8, 2, 3, 4, 5)) self.assertEqual(dt.astimezone(utc_tz).ewsformat(), '2000-08-02T01:04:05Z')
def initEventStorage(): # Open sqlite database, up to now it is used to store calendarNames / Outlook categories and Mattermost groups in which calendar events should be posted. # The calendar events are stored in an Outlook calendar and also in the sqlite database up to now. try: conn = sqlite3.connect(calendarSettings['DatabaseName']) cursor=conn.cursor() except Exception as e: print ("Could not open sqlite database due to following exception:\n {0} \n {1}".format(e.__doc__, e.message)) # Open outlook calendar try: config = Configuration(username=outlookSettings['Username'], password=outlookSettings['Password']) account = Account(primary_smtp_address=outlookSettings['Email'], config=config, autodiscover=True, access_type=DELEGATE) except Exception as e: print ("Could not open Outlook calendar due to following exception:\n {0} \n {1}".format(e.__doc__, e.message)) # Set timezone needed later, note: only Copenhagen is mapped but it is the same timezone as Berlin tz = EWSTimeZone.timezone('Europe/Copenhagen') # Create table which contains subcalendars # calendarName: Name which is refered to add an event, calendarMattermostGroup: group in which events should be published # calendarName is rewritten in an Outlook calendar category to be stored in Outlook calendar try: createCalendarTable = "CREATE TABLE IF NOT EXISTS 'calendarTable' (id INTEGER PRIMARY KEY AUTOINCREMENT, calendarName TEXT, calendarMattermostGroup TEXT)" conn.execute(createCalendarTable) except Exception as e: print ("Could not access / create sqlite calendar due to following exception:\n {0} \n {1}".format(e.__doc__, e.message)) return conn, cursor, tz, account
def test_from_params(self): tz = EWSTimeZone.timezone('Europe/Copenhagen') start = tz.localize(EWSDateTime(1900, 9, 26, 8, 0, 0)) end = tz.localize(EWSDateTime(2200, 9, 26, 11, 0, 0)) xml = Restriction.from_params(start=start, end=end, categories=['FOO', 'BAR']) result = '''\ <m:Restriction> <t:And> <t:IsGreaterThan> <t:FieldURI FieldURI="calendar:End" /> <t:FieldURIOrConstant> <t:Constant Value="1900-09-26T07:10:00Z" /> </t:FieldURIOrConstant> </t:IsGreaterThan> <t:IsLessThan> <t:FieldURI FieldURI="calendar:Start" /> <t:FieldURIOrConstant> <t:Constant Value="2200-09-26T10:00:00Z" /> </t:FieldURIOrConstant> </t:IsLessThan> <t:Or> <t:Contains ContainmentComparison="Exact" ContainmentMode="Substring"> <t:FieldURI FieldURI="item:Categories" /> <t:Constant Value="FOO" /> </t:Contains> <t:Contains ContainmentComparison="Exact" ContainmentMode="Substring"> <t:FieldURI FieldURI="item:Categories" /> <t:Constant Value="BAR" /> </t:Contains> </t:Or> </t:And> </m:Restriction>''' self.assertEqual(str(xml), ''.join(l.lstrip() for l in result.split('\n')))
def setUp(self): self.tz = EWSTimeZone.timezone('Europe/Copenhagen') try: with open(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'settings.yml')) as f: settings = load(f) except FileNotFoundError: print('Copy settings.yml.sample to settings.yml and enter values for your test server') raise self.categories = ['Test'] self.config = Configuration(server=settings['server'], username=settings['username'], password=settings['password']) self.account = Account(primary_smtp_address=settings['account'], access_type=DELEGATE, config=self.config)
def setUp(self): # There's no official Exchange server we can test against, and we can't really provide credentials for our # own test server to anyone on the Internet. You need to create your own settings.yml with credentials for # your own test server. 'settings.yml.sample' is provided as a template. try: with open(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'settings.yml')) as f: settings = load(f) except FileNotFoundError: print('Copy settings.yml.sample to settings.yml and enter values for your test server') raise self.tz = EWSTimeZone.timezone('Europe/Copenhagen') self.categories = ['Test'] self.config = Configuration(server=settings['server'], username=settings['username'], password=settings['password'], verify_ssl=settings['verify_ssl']) self.account = Account(primary_smtp_address=settings['account'], access_type=DELEGATE, config=self.config) self.maxDiff = None
from exchangelib.configuration import Configuration from exchangelib.account import Account from exchangelib.ewsdatetime import EWSDateTime, EWSTimeZone from exchangelib.folders import CalendarItem logging.basicConfig(level=logging.WARNING) try: with open(os.path.join(os.path.dirname(__file__), 'settings.yml')) as f: settings = load(f) except FileNotFoundError: print('Copy settings.yml.sample to settings.yml and enter values for your test server') raise categories = ['perftest'] tz = EWSTimeZone.timezone('Europe/Copenhagen') config = Configuration(server=settings['server'], username=settings['username'], password=settings['password']) print(('Exchange server: %s' % config.protocol.server)) account = Account(config=config, primary_smtp_address=settings['account'], access_type=DELEGATE) cal = account.calendar # Calendar item generator def calitems(): i = 0 start = tz.localize(EWSDateTime(2000, 3, 1, 8, 30, 0)) end = tz.localize(EWSDateTime(2000, 3, 1, 9, 15, 0)) item = CalendarItem( item_id='',
# Disable insecure SSL warnings warnings.filterwarnings("ignore") # Use notify-send for email notifications and zenity for calendar notifications notify = sh.Command('/usr/bin/notify-send') zenity = sh.Command('/usr/bin/zenity') # Get the local timezone timedatectl = sh.Command('/usr/bin/timedatectl') for l in timedatectl(): if 'Timezone' in l: tz_name = l.split()[1] break else: raise ValueError('Timezone not found') tz = EWSTimeZone.timezone(tz_name) sleep = int(sys.argv[1]) # 1st arg to this script is the number of seconds to look back in the inbox now = UTC_NOW() emails_since = now - timedelta(seconds=sleep) cal_items_before = now + timedelta(seconds=sleep * 4) # Longer notice of upcoming appointments than new emails username, _, password = netrc().authenticators('office365') c = Credentials(username, password, is_service_account=False) a = Account(primary_smtp_address=c.username, credentials=c, access_type=DELEGATE, autodiscover=True, verify_ssl=False) for msg in a.calendar.view(start=now, end=cal_items_before)\ .only('start', 'end', 'subject', 'location')\ .order_by('start', 'end'): if msg.start < now: continue minutes_to_appointment = int((msg.start - now).total_seconds() / 60)
def test_ewsdatetime(self): # Test a static timezone tz = EWSTimeZone('Etc/GMT-5') dt = EWSDateTime(2000, 1, 2, 3, 4, 5, 678901, tzinfo=tz) self.assertIsInstance(dt, EWSDateTime) self.assertIsInstance(dt.tzinfo, EWSTimeZone) self.assertEqual(dt.tzinfo.ms_id, tz.ms_id) self.assertEqual(dt.tzinfo.ms_name, tz.ms_name) self.assertEqual(str(dt), '2000-01-02 03:04:05.678901+05:00') self.assertEqual( repr(dt), "EWSDateTime(2000, 1, 2, 3, 4, 5, 678901, tzinfo=EWSTimeZone(key='Etc/GMT-5'))" ) # Test a DST timezone tz = EWSTimeZone('Europe/Copenhagen') dt = EWSDateTime(2000, 1, 2, 3, 4, 5, 678901, tzinfo=tz) self.assertIsInstance(dt, EWSDateTime) self.assertIsInstance(dt.tzinfo, EWSTimeZone) self.assertEqual(dt.tzinfo.ms_id, tz.ms_id) self.assertEqual(dt.tzinfo.ms_name, tz.ms_name) self.assertEqual(str(dt), '2000-01-02 03:04:05.678901+01:00') self.assertEqual( repr(dt), "EWSDateTime(2000, 1, 2, 3, 4, 5, 678901, tzinfo=EWSTimeZone(key='Europe/Copenhagen'))" ) # Test from_string with self.assertRaises(NaiveDateTimeNotAllowed): EWSDateTime.from_string('2000-01-02T03:04:05') self.assertEqual(EWSDateTime.from_string('2000-01-02T03:04:05+01:00'), EWSDateTime(2000, 1, 2, 2, 4, 5, tzinfo=UTC)) self.assertEqual(EWSDateTime.from_string('2000-01-02T03:04:05Z'), EWSDateTime(2000, 1, 2, 3, 4, 5, tzinfo=UTC)) self.assertIsInstance( EWSDateTime.from_string('2000-01-02T03:04:05+01:00'), EWSDateTime) self.assertIsInstance(EWSDateTime.from_string('2000-01-02T03:04:05Z'), EWSDateTime) # Test addition, subtraction, summertime etc self.assertIsInstance(dt + datetime.timedelta(days=1), EWSDateTime) self.assertIsInstance(dt - datetime.timedelta(days=1), EWSDateTime) self.assertIsInstance(dt - EWSDateTime.now(tz=tz), datetime.timedelta) self.assertIsInstance(EWSDateTime.now(tz=tz), EWSDateTime) # Test various input for from_datetime() self.assertEqual( dt, EWSDateTime.from_datetime( datetime.datetime(2000, 1, 2, 3, 4, 5, 678901, tzinfo=EWSTimeZone('Europe/Copenhagen')))) self.assertEqual( dt, EWSDateTime.from_datetime( datetime.datetime( 2000, 1, 2, 3, 4, 5, 678901, tzinfo=zoneinfo.ZoneInfo('Europe/Copenhagen')))) self.assertEqual( dt, EWSDateTime.from_datetime( datetime.datetime( 2000, 1, 2, 3, 4, 5, 678901, tzinfo=dateutil.tz.gettz('Europe/Copenhagen')))) self.assertEqual( dt, EWSDateTime.from_datetime( datetime.datetime(2000, 1, 2, 3, 4, 5, 678901, tzinfo=pytz.timezone('Europe/Copenhagen')))) self.assertEqual(dt.ewsformat(), '2000-01-02T03:04:05.678901+01:00') utc_tz = EWSTimeZone('UTC') self.assertEqual( dt.astimezone(utc_tz).ewsformat(), '2000-01-02T02:04:05.678901Z') # Test summertime dt = EWSDateTime(2000, 8, 2, 3, 4, 5, 678901, tzinfo=tz) self.assertEqual( dt.astimezone(utc_tz).ewsformat(), '2000-08-02T01:04:05.678901Z') # Test in-place add and subtract dt = EWSDateTime(2000, 1, 2, 3, 4, 5, tzinfo=tz) dt += datetime.timedelta(days=1) self.assertIsInstance(dt, EWSDateTime) self.assertEqual(dt, EWSDateTime(2000, 1, 3, 3, 4, 5, tzinfo=tz)) dt = EWSDateTime(2000, 1, 2, 3, 4, 5, tzinfo=tz) dt -= datetime.timedelta(days=1) self.assertIsInstance(dt, EWSDateTime) self.assertEqual(dt, EWSDateTime(2000, 1, 1, 3, 4, 5, tzinfo=tz)) # Test ewsformat() failure dt = EWSDateTime(2000, 1, 2, 3, 4, 5) with self.assertRaises(ValueError): dt.ewsformat() # Test wrong tzinfo type with self.assertRaises(ValueError): EWSDateTime(2000, 1, 2, 3, 4, 5, tzinfo=pytz.timezone('Europe/Copenhagen')) with self.assertRaises(ValueError): EWSDateTime.from_datetime(EWSDateTime(2000, 1, 2, 3, 4, 5))
def random_val(self, field): if isinstance(field, ExtendedPropertyField): if field.value_cls.property_type == "StringArray": return [ get_random_string(255) for _ in range(random.randint(1, 4)) ] if field.value_cls.property_type == "IntegerArray": return [ get_random_int(0, 256) for _ in range(random.randint(1, 4)) ] if field.value_cls.property_type == "BinaryArray": return [ get_random_string(255).encode() for _ in range(random.randint(1, 4)) ] if field.value_cls.property_type == "String": return get_random_string(255) if field.value_cls.property_type == "Integer": return get_random_int(0, 256) if field.value_cls.property_type == "Binary": # In the test_extended_distinguished_property test, EWS rull return 4 NULL bytes after char 16 if we # send a longer bytes sequence. return get_random_string(16).encode() raise ValueError(f"Unsupported field {field}") if isinstance(field, URIField): return get_random_url() if isinstance(field, EmailAddressField): return get_random_email() if isinstance(field, ChoiceField): return get_random_choice( field.supported_choices(version=self.account.version)) if isinstance(field, CultureField): return get_random_choice([ "da-DK", "de-DE", "en-US", "es-ES", "fr-CA", "nl-NL", "ru-RU", "sv-SE" ]) if isinstance(field, BodyField): return get_random_string(400) if isinstance(field, CharListField): return [get_random_string(16) for _ in range(random.randint(1, 4))] if isinstance(field, TextListField): return [ get_random_string(400) for _ in range(random.randint(1, 4)) ] if isinstance(field, CharField): return get_random_string(field.max_length) if isinstance(field, TextField): return get_random_string(400) if isinstance(field, MimeContentField): return get_random_string(400).encode("utf-8") if isinstance(field, Base64Field): return get_random_bytes(400) if isinstance(field, BooleanField): return get_random_bool() if isinstance(field, DecimalField): return get_random_decimal(field.min or 1, field.max or 99) if isinstance(field, IntegerField): return get_random_int(field.min or 0, field.max or 256) if isinstance(field, DateField): return get_random_date() if isinstance(field, DateTimeBackedDateField): return get_random_date() if isinstance(field, DateTimeField): return get_random_datetime(tz=self.account.default_timezone) if isinstance(field, AttachmentField): return [ FileAttachment(name="my_file.txt", content=get_random_string(400).encode("utf-8")) ] if isinstance(field, MailboxListField): # email_address must be a real account on the server(?) # TODO: Mailbox has multiple optional args but vals must match server account, so we can't easily test if get_random_bool(): return [ Mailbox(email_address=self.account.primary_smtp_address) ] return [self.account.primary_smtp_address] if isinstance(field, MailboxField): # email_address must be a real account on the server(?) # TODO: Mailbox has multiple optional args but vals must match server account, so we can't easily test if get_random_bool(): return Mailbox(email_address=self.account.primary_smtp_address) return self.account.primary_smtp_address if isinstance(field, AttendeesField): # Attendee must refer to a real mailbox on the server(?). We're only sure to have one if get_random_bool(): mbx = Mailbox(email_address=self.account.primary_smtp_address) else: mbx = self.account.primary_smtp_address with_last_response_time = get_random_bool() if with_last_response_time: return [ Attendee( mailbox=mbx, response_type="Accept", last_response_time=get_random_datetime( tz=self.account.default_timezone), ) ] if get_random_bool(): return [Attendee(mailbox=mbx, response_type="Accept")] return [self.account.primary_smtp_address] if isinstance(field, EmailAddressesField): addrs = [] for label in EmailAddress.get_field_by_fieldname( "label").supported_choices(version=self.account.version): addr = EmailAddress(email=get_random_email()) addr.label = label addrs.append(addr) return addrs if isinstance(field, PhysicalAddressField): addrs = [] for label in PhysicalAddress.get_field_by_fieldname( "label").supported_choices(version=self.account.version): addr = PhysicalAddress( street=get_random_string(32), city=get_random_string(32), state=get_random_string(32), country=get_random_string(32), zipcode=get_random_string(8), ) addr.label = label addrs.append(addr) return addrs if isinstance(field, PhoneNumberField): pns = [] for label in PhoneNumber.get_field_by_fieldname( "label").supported_choices(version=self.account.version): pn = PhoneNumber(phone_number=get_random_string(16)) pn.label = label pns.append(pn) return pns if isinstance(field, EWSElementField): if field.value_cls == Recurrence: return Recurrence(pattern=DailyPattern(interval=5), start=get_random_date(), number=7) if field.value_cls == TaskRecurrence: return TaskRecurrence(pattern=DailyRegeneration(interval=5), start=get_random_date(), number=7) if field.value_cls == ReminderMessageData: start = get_random_time() end = get_random_time(start_time=start) return ReminderMessageData( reminder_text=get_random_string(16), location=get_random_string(16), start_time=start, end_time=end, ) if field.value_cls == CompleteName: return CompleteName( title=get_random_string(16), first_name=get_random_string(16), middle_name=get_random_string(16), last_name=get_random_string(16), suffix=get_random_string(16), initials=get_random_string(16), full_name=get_random_string(16), nickname=get_random_string(16), yomi_first_name=get_random_string(16), yomi_last_name=get_random_string(16), ) if isinstance(field, TimeZoneField): while True: tz = zoneinfo.ZoneInfo( random.choice(tuple(zoneinfo.available_timezones()))) try: EWSTimeZone.from_zoneinfo(tz) except UnknownTimeZone: continue return tz if isinstance(field, PermissionSetField): return PermissionSet(permissions=[ Permission(user_id=UserId( primary_smtp_address=self.account.primary_smtp_address), ) ]) raise ValueError(f"Unknown field {field}")
def random_val(self, field): if isinstance(field, ExtendedPropertyField): if field.value_cls.property_type == 'StringArray': return [ get_random_string(255) for _ in range(random.randint(1, 4)) ] if field.value_cls.property_type == 'IntegerArray': return [ get_random_int(0, 256) for _ in range(random.randint(1, 4)) ] if field.value_cls.property_type == 'BinaryArray': return [ get_random_string(255).encode() for _ in range(random.randint(1, 4)) ] if field.value_cls.property_type == 'String': return get_random_string(255) if field.value_cls.property_type == 'Integer': return get_random_int(0, 256) if field.value_cls.property_type == 'Binary': # In the test_extended_distinguished_property test, EWS rull return 4 NULL bytes after char 16 if we # send a longer bytes sequence. return get_random_string(16).encode() raise ValueError('Unsupported field %s' % field) if isinstance(field, URIField): return get_random_url() if isinstance(field, EmailAddressField): return get_random_email() if isinstance(field, ChoiceField): return get_random_choice( field.supported_choices(version=self.account.version)) if isinstance(field, CultureField): return get_random_choice([ 'da-DK', 'de-DE', 'en-US', 'es-ES', 'fr-CA', 'nl-NL', 'ru-RU', 'sv-SE' ]) if isinstance(field, BodyField): return get_random_string(400) if isinstance(field, CharListField): return [get_random_string(16) for _ in range(random.randint(1, 4))] if isinstance(field, TextListField): return [ get_random_string(400) for _ in range(random.randint(1, 4)) ] if isinstance(field, CharField): return get_random_string(field.max_length) if isinstance(field, TextField): return get_random_string(400) if isinstance(field, MimeContentField): return get_random_bytes(400) if isinstance(field, Base64Field): return get_random_bytes(400) if isinstance(field, BooleanField): return get_random_bool() if isinstance(field, DecimalField): return get_random_decimal(field.min or 1, field.max or 99) if isinstance(field, IntegerField): return get_random_int(field.min or 0, field.max or 256) if isinstance(field, DateField): return get_random_date() if isinstance(field, DateTimeBackedDateField): return get_random_date() if isinstance(field, DateTimeField): return get_random_datetime(tz=self.account.default_timezone) if isinstance(field, AttachmentField): return [ FileAttachment(name='my_file.txt', content=get_random_bytes(400)) ] if isinstance(field, MailboxListField): # email_address must be a real account on the server(?) # TODO: Mailbox has multiple optional args but vals must match server account, so we can't easily test if get_random_bool(): return [ Mailbox(email_address=self.account.primary_smtp_address) ] else: return [self.account.primary_smtp_address] if isinstance(field, MailboxField): # email_address must be a real account on the server(?) # TODO: Mailbox has multiple optional args but vals must match server account, so we can't easily test if get_random_bool(): return Mailbox(email_address=self.account.primary_smtp_address) else: return self.account.primary_smtp_address if isinstance(field, AttendeesField): # Attendee must refer to a real mailbox on the server(?). We're only sure to have one if get_random_bool(): mbx = Mailbox(email_address=self.account.primary_smtp_address) else: mbx = self.account.primary_smtp_address with_last_response_time = get_random_bool() if with_last_response_time: return [ Attendee(mailbox=mbx, response_type='Accept', last_response_time=get_random_datetime( tz=self.account.default_timezone)) ] else: if get_random_bool(): return [Attendee(mailbox=mbx, response_type='Accept')] else: return [self.account.primary_smtp_address] if isinstance(field, EmailAddressesField): addrs = [] for label in EmailAddress.get_field_by_fieldname( 'label').supported_choices(version=self.account.version): addr = EmailAddress(email=get_random_email()) addr.label = label addrs.append(addr) return addrs if isinstance(field, PhysicalAddressField): addrs = [] for label in PhysicalAddress.get_field_by_fieldname('label')\ .supported_choices(version=self.account.version): addr = PhysicalAddress(street=get_random_string(32), city=get_random_string(32), state=get_random_string(32), country=get_random_string(32), zipcode=get_random_string(8)) addr.label = label addrs.append(addr) return addrs if isinstance(field, PhoneNumberField): pns = [] for label in PhoneNumber.get_field_by_fieldname( 'label').supported_choices(version=self.account.version): pn = PhoneNumber(phone_number=get_random_string(16)) pn.label = label pns.append(pn) return pns if isinstance(field, EWSElementField): if field.value_cls == Recurrence: return Recurrence(pattern=DailyPattern(interval=5), start=get_random_date(), number=7) if isinstance(field, TimeZoneField): while True: try: return EWSTimeZone( random.choice(tuple(zoneinfo.available_timezones()))) except UnknownTimeZone: pass if isinstance(field, PermissionSetField): return PermissionSet(permissions=[ Permission(user_id=UserId( primary_smtp_address=self.account.primary_smtp_address), ) ]) raise ValueError('Unknown field %s' % field)
def test_from_timezone(self): self.assertEqual( EWSTimeZone("Europe/Copenhagen"), EWSTimeZone.from_timezone(EWSTimeZone("Europe/Copenhagen"))) self.assertEqual( EWSTimeZone("Europe/Copenhagen"), EWSTimeZone.from_timezone(zoneinfo.ZoneInfo("Europe/Copenhagen"))) self.assertEqual( EWSTimeZone("Europe/Copenhagen"), EWSTimeZone.from_timezone(dateutil.tz.gettz("Europe/Copenhagen"))) self.assertEqual( EWSTimeZone("Europe/Copenhagen"), EWSTimeZone.from_timezone(pytz.timezone("Europe/Copenhagen"))) self.assertEqual(EWSTimeZone("UTC"), EWSTimeZone.from_timezone(dateutil.tz.UTC)) self.assertEqual(EWSTimeZone("UTC"), EWSTimeZone.from_timezone(datetime.timezone.utc))
notify = sh.Command('/usr/bin/notify-send') zenity = sh.Command('/usr/bin/zenity') # Get the local timezone timedatectl = sh.Command('/usr/bin/timedatectl') for l in timedatectl(): # timedatectl output differs on varying distros if 'Timezone' in l.strip(): tz_name = l.split()[1] break if 'Time zone' in l.strip(): tz_name = l.split()[2] break else: raise ValueError('Timezone not found') tz = EWSTimeZone.timezone(tz_name) sleep = int( sys.argv[1] ) # 1st arg to this script is the number of seconds to look back in the inbox now = UTC_NOW() emails_since = now - timedelta(seconds=sleep) cal_items_before = now + timedelta( seconds=sleep * 4) # Longer notice of upcoming appointments than new emails username, _, password = netrc().authenticators('office365') c = Credentials(username, password, is_service_account=False) a = Account(primary_smtp_address=c.username, credentials=c, access_type=DELEGATE, autodiscover=True,
top.geometry('%dx%d+%d+%d' % (w, h, x, y)) top.update() credentials = Credentials( username='******', # Or [email protected] for O365 password='******') account = Account(primary_smtp_address='*****@*****.**', credentials=credentials, autodiscover=True, access_type=DELEGATE) yardAccount = Account(primary_smtp_address='*****@*****.**', credentials=credentials, autodiscover=True, access_type=DELEGATE) done = [] tz = EWSTimeZone.localzone() Message.register('flag', Flag) top.after(0, doStuff, credentials, yardAccount, account, done) top.mainloop() # print("quitting") # sleep(2) # print("beofre") # try: # # driver.close() # driver.quit() # except: # print(exc_info()) # print("aftr") # sleep(10) # pyinstaller "C:\Users\ssleep\workspace\RNS Releaser\Automator\__init__.py" --distpath "J:\Spencer\RNS Releaser" -y
from exchangelib.configuration import Configuration from exchangelib.account import Account from exchangelib.ewsdatetime import EWSDateTime, EWSTimeZone from exchangelib.folders import CalendarItem logging.basicConfig(level=logging.WARNING) try: with open(os.path.join(os.path.dirname(__file__), 'settings.yml')) as f: settings = load(f) except FileNotFoundError: print('Copy settings.yml.sample to settings.yml and enter values for your test server') raise categories = ['foobar', 'perftest'] tz = EWSTimeZone.timezone('US/Pacific') t0 = datetime.now() config = Configuration(server=settings['server'], username=settings['username'], password=settings['password'], verify_ssl=False) print(('Exchange server: %s' % config.protocol.server)) account = Account(config=config, primary_smtp_address=settings['account'], access_type=DELEGATE) cal = account.calendar t1 = datetime.now() print(('Time to build ExchangeServer object: %s' % (t1 - t0))) year = 2012 month = 3