def __init__(self, calendar_timezone, calendar_location):
        gmail_account = get_account_info(configs[CONFIG_KEY_GMAIL_ACCOUNT],
                                         GMAIL_PROMPT)
        gmail_pwd = get_account_info(configs[CONFIG_KEY_GMAIL_PWD],
                                     PASSWORD_PROMPT,
                                     True)

        self.client = gdata.calendar.client.CalendarClient(
            source=GoogleCalendarProxy.app_source
        )

        try:
            info('logging in as %s' % gmail_account)
            self.client.ClientLogin(gmail_account, gmail_pwd,
                                    self.client.source)

            for calendar in self.client.GetOwnCalendarsFeed().entry:
                if calendar.summary and\
                   calendar.summary.text == configs[CONFIG_KEY_THIS_CALENDAR_SUMMARY]:
                    if configs[CONFIG_KEY_IF_THIS_CALENDAR_FOUND_THEN_PERFORM_DELETE]:
                        info('previously created calendar %s found,'
                             'deleting' % calendar.title.text)
                        self.client.Delete(calendar.GetEditLink().href)
                        self.current_calendar = self.client.InsertCalendar(
                            new_calendar=self.gen_calender(
                                configs[CONFIG_KEY_THIS_CALENDAR_TITLE],
                                configs[CONFIG_KEY_THIS_CALENDAR_SUMMARY],
                                configs[CONFIG_KEY_THIS_CALENDAR_COLOR],
                                calendar_timezone,
                                calendar_location
                            )
                        )
                    else:
                        self.current_calendar = calendar
                    break
            else:
                self.current_calendar = self.client.InsertCalendar(
                    new_calendar=self.gen_calender(
                        configs[CONFIG_KEY_THIS_CALENDAR_TITLE],
                        configs[CONFIG_KEY_THIS_CALENDAR_SUMMARY],
                        configs[CONFIG_KEY_THIS_CALENDAR_COLOR],
                        calendar_timezone,
                        calendar_location
                    )
                )
            dbg('calendar id = %s' % self.current_calendar.content.src)

        except gdata.client.RequestError as e:
            err(e)
            return
Exemple #2
0
def read_configs():
    global ConfigRead

    try:
        dbg('trying to load CONFIG')
        dbg('current working directory: %s' % os.getcwd())
        f = unicode(open('CONFIG', 'r').read(), 'utf-8')

        for line in f.split(u'\n'):
            if line.startswith(u'#'):
                continue

            if u'=' in line:
                l = [s.strip() for s in line.split(u'=')]
                if l[0] in configs:
                    dbg('config %s found, value=%s' % (l[0], eval(l[1])))
                    configs[l[0]] = eval(l[1])
                else:
                    err('unrecognized config parameter %s' % l[0])

    except IOError as e:
        if e.errno == 2:
            dbg('CONFIG not found, using default config')
            return
        else:
            err('error while loading CONFIG')
            return
Exemple #3
0
def grab_courses(session,
                 page_url=MY_COURSES_URL,
                 parser=None):
    dbg('pageURL=%s' % page_url)

    info('retrieving course data of url %s' % page_url)
    response = session.get(page_url)

    d = pq(response.text)
    pq_course_data = d('tr.TR_BODY[align="center"]')
    if parser:
        return parser(pq_course_data)
    else:
        return pq_course_data