pyFitbit is a CLI tool for managing Fitbit OAuth tokens and extracting intraday heart rate data. The tool provides an easy way to authenticate with Fitbit, refresh tokens, and retrieve detailed heart rate data for specified dates or date ranges. Ideal for developers and data analysts working with Fitbit data, this tool streamlines the process of accessing and managing Fitbit health data programmatically.
-
OAuth Token Management: Authenticate and refresh Fitbit OAuth tokens effortlessly.
-
Data Extraction: Extract intraday heart rate data for specific dates or date ranges.
-
Configurable: Easily configure your Fitbit app credentials via a
config.json
file.
-
Clone the repository:
git clone https://github.com/your-username/pyfitbit.git cd pyfitbit
-
Install the required dependencies:
pip install -r requirements.txt
-
Install the CLI tool:
pip install --editable .
Create a config.json
file with your Fitbit app credentials and API settings. Here is an example:
{
"fitbit": {
"authorize_uri": "https://www.fitbit.com/oauth2/authorize",
"client_id": "your_client_id",
"client_secret": "your_client_secret",
"redirect_uri": "your_redirect_uri"
}
}
To authenticate and get the authorization token for a Fitbit email:
pyfitbit token -auth [email protected]
To refresh the tokens for a Fitbit email:
pyfitbit token -refresh [email protected]
pyfitbit extract intraday-heart-rate date [email protected]
To extract intraday heart rate data for a date range:
pyfitbit extract intraday-heart-rate start_date end_date [email protected]
- auth: Handles the OAuth autharization process and saves the tokens.
- refresh: Refreshes the tokens and save new tokens.
- intraday_heart_rate: Extracts intraday heart rate data for a given date or date range.
- get_config: Loads the configuration from
config.json
. - save_tokens: Saves token to
token.json
. - save_refresh_tokens: Saves refreshed tokens to
refresh_tokens.json
. - get_refresh_tokens: Retrieves tokens from
refresh_tokens.json
. - validate_date: Validates the date format.
- validate_email: Validates the email format.
- fetch_heart_rate_data_for_date: Fetches heart rate data for a specific date.
# Authenticate and get tokens
pyfitbit token -auth [email protected]
# Refresh tokens
pyfitbit token -refresh [email protected]
# Extract intraday heart rate data for a single date
pyfitbit extract intraday-heart-rate 2023-07-01 [email protected]
# Extract intraday heart rate data for a date range
pyfitbit extract intraday-heart-rate 2023-07-01 2023-07-07 [email protected]
This project is licensed under the MIT License.