Exemple #1
0
def process_goals():

    previous_goal_states = get_stored_goal_states(
        settings.STORED_GOAL_STATES_LOCATION)

    logging.info("Processing goal state-changes")
    evernote_client = EvernoteConnector(token=settings.EVERNOTE_AUTH_TOKEN,
                                        sandbox=settings.EVERNOTE_SANDBOX_MODE)
    new_goal_states = evernote_client.process_goal_updates(
        previous_goal_states)

    save_stored_goal_states(settings.STORED_GOAL_STATES_LOCATION,
                            new_goal_states)
    logging.info("Completed processing goals")
Exemple #2
0
def process_events():

    current_check_time = None

    # Get new events from Evernote
    logging.info("Getting new events from Evernote")
    evernote_client = EvernoteConnector(token=settings.EVERNOTE_AUTH_TOKEN,
                                        sandbox=settings.EVERNOTE_SANDBOX_MODE)
    try:
        current_check_time = datetime.now().strftime("%Y%m%dT%H%M%S")
        last_successful_check_time = get_last_successful_check_time(
            settings.LATEST_CHECK_TIME_LOCATION)

        logging.debug("Last successful check was " +
                      last_successful_check_time)

        events = evernote_client.get_new_events(
            since=last_successful_check_time)
        logging.debug("Evernote connection was successful")

    except EvernoteConnectorException as e:
        logging.critical("There was an error with the EvernoteConnector: " +
                         e.msg)
        return

    logging.info('Found ' + str(len(events)) + ' new events:')

    for event in events:
        logging.debug('StartTime: ' +
                      event.start_time.strftime('%Y-%m-%d %H%M') +
                      ', EndTime: ' +
                      event.end_time.strftime('%Y-%m-%d %H%M') + ", Title: '" +
                      event.title + "'")

    # Add new events to Google Calender

    if len(events) > 0:
        logging.info('Adding new events to Google Calendar')
        google_client = GoogleCalendarConnector(
            credentials_file=settings.GOOGLE_CREDENTIALS_FILE)
        google_client.add_new_events(events)

    save_successful_check_time(settings.LATEST_CHECK_TIME_LOCATION,
                               current_check_time)
    logging.info('Completed processing events, saved check time as ' +
                 current_check_time)
Exemple #3
0
def summarise_log():

    print("Summarising the log")
    logging.info("Summarising the daily logs into a weekly log")

    # concatenate all the daily logs for the week
    # create a new note in weekly logs with that content

    # The week is Monday 00:00:00 to Sunday 23:59:59
    start_time = get_start_of_week(datetime.now())
    end_time = get_end_of_week(datetime.now())

    try:
        evernote_client = EvernoteConnector(
            token=settings.EVERNOTE_AUTH_TOKEN,
            sandbox=settings.EVERNOTE_SANDBOX_MODE)

        summary_content = evernote_client.get_concatenated_daily_logs(
            start_time, end_time)

        first_day_of_this_week = datetime.now() - timedelta(
            days=datetime.now().weekday())
        summary_title = datetime.strftime(first_day_of_this_week,
                                          "W/C %Y-%m-%d")

        evernote_client.create_summary_log("Summaries", summary_title,
                                           summary_content)

        logging.info("Completed summarising the daily logs into a weekly log")

    except EvernoteConnectorException as e:
        logging.critical("There was an error with the EvernoteConnector: " +
                         e.msg)
        return

    print("Completed summarising the log")