Exemple #1
0
def run_new_token():
    config = ConfigHelper()
    config.load()  # because we do not want to override the other settings

    DualisService(config).interactively_acquire_token()

    print('New Token successfully saved!')
Exemple #2
0
def run_change_notification_mail():
    config = ConfigHelper()
    config.load()

    MailService(config).interactively_configure()

    print('Configuration successfully updated!')
Exemple #3
0
def run_main():
    logging.basicConfig(
        filename='DualisWatcher.log', level=logging.DEBUG,
        format='%(asctime)s  %(levelname)s  {%(module)s}  %(message)s', datefmt='%Y-%m-%d %H:%M:%S'
    )

    logging.info('--- main started ---------------------')
    if IS_DEBUG:
        logging.info('Debug-Mode detected. Errors will not be logged but instead re-risen.')
        debug_logger = logging.getLogger()
        debug_logger.setLevel(logging.ERROR)
        debug_logger.addHandler(ReRaiseOnError())

    try:
        logging.debug('Loading config...')
        config = ConfigHelper()
        config.load()
    except BaseException as e:
        logging.error('Error while trying to load the Configuration! Exiting...', extra={'exception':e})
        sys.exit(-1)

    mail_service = MailService(config)

    try:
        dualis = DualisService(config)

        logging.debug('Checking for changes for the configured Dualis-Account....')
        results = dualis.fetch_and_check_state()
        changes = results[0]
        course_names = results[1]

        if changes.diff_count > 0:
            logging.info('%s changes found for the configured Dualis-Account.'%(changes.diff_count))
            token = dualis.get_token()
            mail_service.notify_about_changes_in_results(changes, course_names, token)
            dualis.save_state()
        else:
            logging.info('No changes found for the configured Dualis-Account.')

        schedule = ScheduleService(config)
        if schedule.is_activated:
            logging.debug('Checking for changes for the configured Schedule...')
            changes = schedule.fetch_and_check_state()
            if len(changes) > 0:
                logging.info('%s changes found for the configured Schedule.'%(len(changes)))
                mail_service.notify_about_changes_in_schedule(changes, schedule.uid)
                schedule.save_state()
            else:
                logging.info('No changes found for the configured Schedule.')

        logging.debug('All done. Exiting...')
    except BaseException as e:
        error_formatted = traceback.format_exc()
        logging.error(error_formatted, extra={'exception':e})
        mail_service.notify_about_error(str(e))
        logging.debug('Exception-Handling completed. Exiting...', extra={'exception' : e})
        sys.exit(-1)
Exemple #4
0
def run_new_token(email='', password=''):
    config = ConfigHelper()
    config.load()  # because we do not want to override the other settings

    if (not email or not password):
        DualisService(config).interactively_acquire_token()
    else:
        DualisService(config).acquire_token(email, password)

    print('New Token successfully saved!')
Exemple #5
0
def run_change_schedule_watcher():
    config = ConfigHelper()
    config.load()

    schedule = ScheduleService(config)

    schedule.interactively_configure()
    print('Configuration successfully updated!')

    print('Fetching current states as base...')
    schedule.fetch_and_save_unchecked_state()
    print('done!')
Exemple #6
0
def run_new_token(email='', password=''):
    config = ConfigHelper()
    config.load()  # because we do not want to override the other settings

    logging.basicConfig(
        filename='DualisWatcher.log',
        level=logging.DEBUG,
        format='%(asctime)s  %(levelname)s  {%(module)s}  %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S')

    logging.info('--- run_new_token started ---------------------')

    if (not email or not password):
        DualisService(config).interactively_acquire_token()
    else:
        DualisService(config).acquire_token(email, password)

    print('New Token successfully saved!')
Exemple #7
0
def run_main():
    logging.basicConfig(
        filename='DualisWatcher.log',
        level=logging.DEBUG,
        format='%(asctime)s  %(levelname)s  {%(module)s}  %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S')

    logging.info('--- main started ---------------------')
    if IS_DEBUG:
        logging.info(
            'Debug-Mode detected. Errors will not be logged but instead re-risen.'
        )
        debug_logger = logging.getLogger()
        debug_logger.setLevel(logging.ERROR)
        debug_logger.addHandler(ReRaiseOnError())

    try:
        logging.debug('Loading config...')
        config = ConfigHelper()
        config.load()
    except BaseException as e:
        logging.error(
            'Error while trying to load the Configuration! Exiting...',
            extra={'exception': e})
        sys.exit(-1)

    r_client = None
    try:
        sentry_dsn = config.get_property('sentry_dsn')
        if sentry_dsn:
            r_client = RavenClient(sentry_dsn,
                                   auto_log_stacks=True,
                                   release=fetch_git_sha(
                                       os.path.dirname(__file__)))
    except BaseException:
        pass

    mail_service = MailService(config)

    try:
        dualis = DualisService(config)

        logging.debug(
            'Checking for changes for the configured Dualis-Account....')
        results = dualis.fetch_and_check_state()
        changes = results[0]
        course_names = results[1]

        if changes.diff_count > 0:
            logging.info(
                '%s changes found for the configured Dualis-Account.' %
                (changes.diff_count))
            mail_service.notify_about_changes_in_results(changes, course_names)
            dualis.save_state()
        else:
            logging.info('No changes found for the configured Dualis-Account.')

        schedule = ScheduleService(config)
        if schedule.is_activated:
            logging.debug(
                'Checking for changes for the configured Schedule...')
            changes = schedule.fetch_and_check_state()
            if len(changes) > 0:
                logging.info('%s changes found for the configured Schedule.' %
                             (len(changes) - 1))
                mail_service.notify_about_changes_in_schedule(
                    changes, schedule.uid)
                schedule.save_state()
            else:
                logging.info('No changes found for the configured Schedule.')

        logging.debug('All done. Exiting...')
    except DualisSleepingError:
        logging.info('Dualis is sleeping, exiting and soon trying again.')
        sys.exit(-1)
    except BaseException as e:
        error_formatted = traceback.format_exc()
        logging.error(error_formatted, extra={'exception': e})

        if r_client:
            r_client.captureException(exec_info=True)

        mail_service.notify_about_error(str(e))

        logging.debug('Exception-Handling completed. Exiting...',
                      extra={'exception': e})
        sys.exit(-1)