def update_meetings(res, start_time, subject, URL, USERNAME, PASSWORD):
    if res == "ok":
        print("ok")
        # Set up the connection to Exchange
        connection = ExchangeNTLMAuthConnection(url=URL,
                                                username=USERNAME,
                                                password=PASSWORD)

        service = Exchange2010Service(connection)
        events = service.calendar().list_events(
            start=timezone("US/Pacific").localize(
                datetime(2018, 11, 5, 7, 0, 0)),
            end=timezone("US/Pacific").localize(datetime(2018, 11, 7, 4, 0,
                                                         0)),
            details=True,
            delegate_for=None)

        for events in events.events:
            if str(events.start) == '2018-11-06 00:00:00+00:00':
                # print ("------\n Object Type = {type_events}\n start_time = {start}\n end_time = {stop} \n Subject = {subject} \n Organizer = {organiser}\n events_id = {events_id}\n--------------".format(
                #     start=events.start,
                #     stop=events.end,
                #     subject=events.subject,
                #     organiser = events.organizer.email,
                #     type_events = type(events),
                #     events_id = events.id
                # ))
                new_start = events.start + timedelta(minutes=10)
                events.start = new_start
                events.update()
                print('Completed Updating the meeting')

    else:
        print("Not Updating the meeting")
def list_meetings_and_save_in_DB(room_name):
    ###credentials for outlook exchange:
    URL = u'https://mail.cisco.com/ews/exchange.asmx'
    USERNAME = u'jgerardf'
    PASSWORD = u"Abcd$127"

    # Set up the connection to Exchange
    connection = ExchangeNTLMAuthConnection(url=URL,
                                            username=USERNAME,
                                            password=PASSWORD)

    service = Exchange2010Service(connection)

    val = u'{}'.format(room_name)

    print(room_name, val)
    events = service.calendar().list_events(
        start=timezone("US/Pacific").localize(datetime(2018, 11, 8, 7, 0, 0)),
        end=timezone("US/Pacific").localize(datetime(2018, 11, 10, 7, 0, 0)),
        details=True,
        delegate_for=val)
    truncate_query = "TRUNCATE TABLE outlook_meetings"

    mysql_connection(truncate_query)

    for events in events.events:
        insert_query = "INSERT INTO outlook_meetings(event_id,event_subject,event_organizer,event_start,event_end,event_start_utc,event_end_utc) VALUES('{}','{}','{}','{}','{}','{}','{}')".format(
            events.id, events.subject, events.organizer.email,
            convert_to_pacific(events.start), convert_to_pacific(events.end),
            events.start, events.end)

        #print(insert_query)

        mysql_connection(
            insert_query)  ##calling to insert meetings info into DB
Esempio n. 3
0
    def ews_connection(self):
        '''This connection for sending the meeting invite, which don't support by exchangelib'''
        if not self._ews_connection:
            configuration = ExchangeNTLMAuthConnection(url=self.url,
                                                       username=self.username,
                                                       password=self.password)
            self._ews_connection = Exchange2010Service(configuration)

        return self._ews_connection
Esempio n. 4
0
    def __init__(self, domain, url, username, password, timezone):
        super(ExchangeCalendar, self).__init__()

        self.timezone = timezone

        connection = ExchangeNTLMAuthConnection(url=url,
                                                username='******' %
                                                (domain, username),
                                                password=password)
        self._service = Exchange2010Service(connection)
        self.calendar = self._service.calendar()
def get_calendar_events_cocus():
    URL = u'https://smtp.sfp-net.com/EWS/Exchange.asmx'
    USERNAME = config.outlook_username
    PASSWORD = read_password()

    # Set up the connection to Exchange
    connection = ExchangeNTLMAuthConnection(url=URL,
                                            username=USERNAME,
                                            password=PASSWORD)

    service = Exchange2010Service(connection)

    my_calendar = service.calendar()

    start = datetime.combine(date.today(), time.min)
    end = datetime.combine(date.today(), time.max)

    events = my_calendar.list_events(start, end)
    # details = events.load_all_details()

    event_list = []
    if events:
        for event in events.events:

            event_date = event.start.date().isoformat()
            event_start_time = (event.start + timedelta(hours=1)).time().isoformat()
            event_end_time = (event.end + timedelta(hours=1)).time().isoformat()

            # if 'Nao' in event.subject and 'Home' in event.subject:
            #    print('Maybe found do not use home office')
            #    print('Event %s on %s. From %s until %s' %
            #          (event.subject, event_date, event_start_time, event_end_time))
            #    continue  # ignore event

            print('Event %s on %s. From %s until %s' % (event.subject, event_date, event_start_time, event_end_time))
            now = datetime.now(timezone.utc) + timedelta(hours=1)
            print(now)

            if event.start + timedelta(hours=1) <= now <= event.end + timedelta(hours=1):
                is_happening_now = True
            else:
                is_happening_now = False

            # events_filtered += filter_out_events(event)
            if is_happening_now:
                event_list += filter_out_events(event)

    event_list = event_list[0] if event_list else False

    return event_list
Esempio n. 6
0
    def _get_service(self, username, password):
        """
        Get the calendar for the given connection
        """
        connection = ExchangeNTLMAuthConnection(
            url=self.asmx_url,
            username='******'.format(
                domain=self.domain,
                username=username,
            ),
            password=password)

        service = Exchange2010Service(connection)

        return service
Esempio n. 7
0
def get_events_from_exchange():
    conf = config['Exchange']
    verify_cert = conf.getboolean('VerifyCert', True)

    # Disable SSL warnings when certification verification is turned off
    if not verify_cert:
        requests.packages.urllib3.disable_warnings()

    decrypted_password = base64.b64decode(conf['Password']).decode('utf-8')
    connection = ExchangeNTLMAuthConnection(url=conf['URL'],
                                            username=conf['Username'],
                                            password=decrypted_password,
                                            verify_certificate=verify_cert)
    service = Exchange2010Service(connection)
    calendar = service.calendar()

    return calendar.list_events(start=start_date, end=end_date, details=True)
Esempio n. 8
0
    def initialize(self):
        """
        Initialize connection and schedule periodic events.
        """
        # Loading optional modules only when module is configured.
        from pyexchange import Exchange2010Service
        from pyexchange import ExchangeNTLMAuthConnection

        self.connection = ExchangeNTLMAuthConnection(url=self.url,
                                                     username=self.username,
                                                     password=self.password)
        self.service = Exchange2010Service(self.connection)
        self.exch_calendar = self.service.calendar()
        self.connection.build_session()

        if self.ca_path is not None:
            self.connection.session.verify = self.ca_path

        # Initial refresh
        self.refresh_events()
        self.scheduler.every(60 * 10).seconds.do(self.refresh_events)
Esempio n. 9
0
File: bot.py Progetto: r-soc/ergigit
def give_events(message):
    # Set up the connection to Exchange
    from pyexchange import Exchange2010Service, ExchangeNTLMAuthConnection

    connection = ExchangeNTLMAuthConnection(url=config.ExchangeUrl,
                                            username=config.ExchangeUsername,
                                            password=config.ExchangePassword)

    try:
        service = Exchange2010Service(connection)

        curday = datetime.datetime.now()
        events = my_calendar.list_events(curday, curday)
        events.load_all_details()
        bot.send_message(message.chat.id,
                         events.load_all_details(),
                         parse_mode="Markdown")
    except LookupError:
        bot.send_message(message.chat.id,
                         "Не удалост прочитать Календарь",
                         parse_mode="Markdown")
def update_meetings(res, start_time, subject, URL, USERNAME, PASSWORD):
    if res == "ok":
        print("ok")
        # Set up the connection to Exchange
        connection = ExchangeNTLMAuthConnection(url=URL,
                                                username=USERNAME,
                                                password=PASSWORD)

        service = Exchange2010Service(connection)
        events = service.calendar().list_events(
            start=timezone("US/Pacific").localize(
                datetime(2018, 11, 8, 7, 0, 0)),
            end=timezone("US/Pacific").localize(datetime(
                2018, 11, 10, 7, 0, 0)),
            details=True,
            delegate_for=None)

        for events in events.events:
            #print(events.start)
            if str(events.start) == start_time:
                print(
                    "------\n Object Type = {type_events}\n start_time = {start}\n end_time = {stop} \n Subject = {subject} \n Organizer = {organiser}\n events_id = {events_id}\n--------------"
                    .format(start=events.start,
                            stop=events.end,
                            subject=events.subject,
                            organiser=events.organizer.email,
                            type_events=type(events),
                            events_id=events.id))
                # new_start = events.start+timedelta(minutes=10)
                # events.start = new_start
                # events.update()
                # print('Completed Updating the meeting')
            # else:
            #     #print('time did not match to find the required calendar object')

    else:
        print("Not Updating the meeting")
Esempio n. 11
0
def main(argv):
    try:
        opts, args = getopt.getopt(argv, "h:u:", ["host=", "user="******"-h", "--host"):
            host = a
        elif o in ("-u", "--user"):
            user = a

    pwd = getpass.getpass("Password for your outlook/exchange account: ")
    if not pwd:
        print 'You need to set the password!'
        sys.exit(2)

    connection = ExchangeNTLMAuthConnection(url=host,
                                            username=user,
                                            password=pwd)
    service = Exchange2010Service(connection)

    today = datetime.today()
    nextWeek = today + timedelta(days=7)

    events = service.calendar().list_events(start=today, end=nextWeek)

    for event in events.events:
        print "{start} {stop} - {subject}".format(start=event.start,
                                                  stop=event.end,
                                                  subject=event.subject)

    sys.exit(0)
Esempio n. 12
0

if __name__ == '__main__':

    try:
        mode = sys.argv[1]
    except IndexError:
        mode = 'normal'

    URL = 'https://mymail.qualcomm.com/EWS/Exchange.asmx'
    USERNAME = r'NA\jsmiller'
    PASSWORD = get_password()

    # Set up the connection to Exchange
    connection = ExchangeNTLMAuthConnection(url=URL,
                                            username=USERNAME,
                                            password=PASSWORD)

    service = Exchange2010Service(connection)

    my_calendar = service.calendar()

    local_tz = pytz.timezone("US/Pacific")

    now = datetime.now()
    this_morning = datetime(now.year, now.month, now.day, 0, 1, 0)
    this_evening = datetime(now.year, now.month, now.day, 23, 59, 0)
    with stderr_off():
        events = my_calendar.list_events(
            start=local_tz.localize(this_morning).astimezone(pytz.utc),
            end=local_tz.localize(this_evening).astimezone(pytz.utc),
Esempio n. 13
0
 def connect(self, username, password):
     self.connection = ExchangeNTLMAuthConnection(url=OUTLOOK_URL, username=username, password=password)
     self.service = Exchange2010Service(self.connection)
Esempio n. 14
0
def connectEx():
    global exconnection, service
    exconnection = ExchangeNTLMAuthConnection(url=EX_URL,
                                              username=EX_USERNAME,
                                              password=EX_PASSWORD)
    service = Exchange2010Service(exconnection)
Esempio n. 15
0
from datetime import datetime
from pytz import timezone
from pyexchange import Exchange2010Service, ExchangeNTLMAuthConnection
from Event import Event

originURL = u'https://nomeDoServidor.outlook.com/EWS/Exchange.asmx'
originUsername = u'nomeDoUsuario'
originPassword = u"passwordDoUsuario"

# Set up the connection to Exchange
originConnection = ExchangeNTLMAuthConnection(url=originURL,
                                        username=originUsername,
                                        password=originPassword)

originService = Exchange2010Service(originConnection)

originCalendar = originService.calendar()

originEvents = originCalendar.list_events(
    start=timezone("America/Sao_Paulo").localize(datetime(2017, 11, 1, 0, 0, 0)),
    end=timezone("America/Sao_Paulo").localize(datetime(2017, 11, 17, 0, 0, 0)),
    details=True
)


destinyURL = u'https://outroServidor.outlook.com/EWS/Exchange.asmx'
destinyUsername = u'nomeUsuario'
originPassword = u'passwordUsuario'

# Set up the connection to Exchange
destinyConnection = ExchangeNTLMAuthConnection(url=destinyURL,
Esempio n. 16
0
import keyring
from pytz import timezone
from datetime import datetime
from pyexchange import Exchange2010Service, ExchangeNTLMAuthConnection
import json

credentials = json.load(open('calendarid.json'))

USERNAME = credentials["exchange"][0]["email"]
PASSWORD = keyring.get_password("ExchangeCalShopDirect", USERNAME)
URL = credentials["exchange"][0]["URL"]

print(PASSWORD)
# Set up the connection to Exchange
connection = ExchangeNTLMAuthConnection(
    url=URL, username="******", password=PASSWORD)

service = Exchange2010Service(connection)

my_calendar = service.calendar()

events = my_calendar.list_events(
    start=timezone("Europe/London").localize(datetime(2018, 01, 5)),
    end=timezone("Europe/London").localize(datetime(2018, 01, 10)),
    details=True)

for event in events:
    print "{start} {stop} - {subject}".format(start=event.start,
                                              stop=event.end,
                                              subject=event.subject)
Esempio n. 17
0
def establishexconn():
    global exservice
    exconnection = ExchangeNTLMAuthConnection(url=EX_URL,
                                              username=EX_USERNAME,
                                              password=EX_PASSWORD)
    exservice = Exchange2010Service(exconnection)