Ejemplo n.º 1
0
def test_insert_steps_intraday():
    activity = Activity(
        config={'database': 'fitbit_test',
                'table': 'calories',
                'sum_column': 'total',
                'base_date': '2020-12-26'
                }
    )
    database = Database('fitbit_test', 'activity')
    response = activity.insert_steps_intraday(database)
Ejemplo n.º 2
0
def batch_load_steps(start_date='2020-01-01', end_date='2021-01-01'):
    start_date = date(2021, 1, 1)  # start date
    database = Database('fitbit', 'activity')
    # end_date = set_batch_end_date(database, start_date)
    end_date = date(2021, 1, 6)  # end date
    delta = end_date - start_date  # as timedelta
    activity_api = Activity(config={'base_date': ''})

    for i in tqdm(list(reversed(range(delta.days + 1)))):
        day = start_date + timedelta(days=i)
        activity_api.config['base_date'] = day
        response = activity_api.insert_steps_intraday(database)
        print(response)
Ejemplo n.º 3
0
def get_steps_for_day():
    steps_last_time = 0
    steps_this_time = 0

    sdate = date(2020, 1, 1)  # start date
    edate = date(2021, 1, 2)  # end date

    delta = edate - sdate  # as timedelta
    activity_api = Activity(config={'base_date': ''})

    for i in range(delta.days + 1):
        day = sdate + timedelta(days=i)
        activity_api.config['base_date'] = day
        response = activity_api.insert_steps_intraday()

        steps_this_time = response['summary']['steps']
        dt = datetime.now()

        with open('steps.csv', 'a') as f:
            f.write(f"{steps_this_time},{dt}\n")

        # Show notification whenever needed
        toaster.show_toast(
            "Fitnick Alert",
            f"You have taken {steps_this_time} steps so far today! Keep it up!",
            threaded=False,
            icon_path=None,
            duration=3  # 3 seconds
        )

        print(str(steps_this_time), str(steps_last_time))

        toaster.show_toast(
            "Fitnick Alert",
            f"You took {steps_this_time - steps_last_time} steps since my last alert!",
            threaded=False,
            icon_path=None,
            duration=5)

        steps_last_time = steps_this_time
        for _ in tqdm(range(0, 600)):
            sleep(1)

    return int(steps_this_time)