|
| 1 | +# pyFitbit |
| 2 | + |
| 3 | +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. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **OAuth Token Management**: Authenticate and refresh Fitbit OAuth tokens effortlessly. |
| 8 | +- **Data Extraction**: Extract intraday heart rate data for specific dates or date ranges. |
| 9 | +- **Configurable**: Easily configure your Fitbit app credentials via a `config.json` file. |
| 10 | + |
| 11 | + ## Installation |
| 12 | + |
| 13 | +1. Clone the repository: |
| 14 | + |
| 15 | + ```sh |
| 16 | + git clone https://github.com/your-username/pyfitbit.git |
| 17 | + cd pyfitbit |
| 18 | + ``` |
| 19 | + |
| 20 | +2. Install the required dependencies: |
| 21 | + |
| 22 | + ```sh |
| 23 | + pip install -r requirements.txt |
| 24 | + ``` |
| 25 | + |
| 26 | +3. Install the CLI tool: |
| 27 | + |
| 28 | + ```sh |
| 29 | + pip install --editable . |
| 30 | + ``` |
| 31 | + |
| 32 | +## Configuration |
| 33 | + |
| 34 | +Create a `config.json` file with your Fitbit app credentials and API settings. Here is an example: |
| 35 | + |
| 36 | +```json |
| 37 | +{ |
| 38 | + "fitbit": { |
| 39 | + "authorize_uri": "https://www.fitbit.com/oauth2/authorize", |
| 40 | + "client_id": "your_client_id", |
| 41 | + "client_secret": "your_client_secret", |
| 42 | + "redirect_uri": "your_redirect_uri" |
| 43 | + } |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +## Usage |
| 48 | + |
| 49 | +### 1. OAuth Token Management |
| 50 | + |
| 51 | +#### Authenticate and Get Tokens |
| 52 | + |
| 53 | +To authenticate and get the authorization token for a Fitbit email: |
| 54 | + |
| 55 | +```sh |
| 56 | +pyfitbit token -auth [email protected] |
| 57 | +``` |
| 58 | + |
| 59 | +#### Refresh Tokens |
| 60 | + |
| 61 | +To refresh the tokens for a Fitbit email: |
| 62 | + |
| 63 | +```sh |
| 64 | +pyfitbit token -refresh [email protected] |
| 65 | +``` |
| 66 | + |
| 67 | +### 2. Data Extraction |
| 68 | + |
| 69 | +#### Extract intraday heart rate data for a specific date: |
| 70 | + |
| 71 | +```sh |
| 72 | +pyfitbit extract intraday-heart-rate date [email protected] |
| 73 | +``` |
| 74 | + |
| 75 | +To extract intraday heart rate data for a date range: |
| 76 | + |
| 77 | +```sh |
| 78 | +pyfitbit extract intraday-heart-rate start_date end_date [email protected] |
| 79 | +``` |
| 80 | + |
| 81 | +## Code Overview |
| 82 | + |
| 83 | +### Token Management |
| 84 | + |
| 85 | +- **auth**: Handles the OAuth autharization process and saves the tokens. |
| 86 | +- **refresh**: Refreshes the tokens and save new tokens. |
| 87 | + |
| 88 | +### Data Extraction |
| 89 | + |
| 90 | +- **intraday_heart_rate**: Extracts intraday heart rate data for a given date or date range. |
| 91 | + |
| 92 | +### Utility Functions |
| 93 | + |
| 94 | +- **get_config**: Loads the configuration from `config.json`. |
| 95 | +- **save_tokens**: Saves token to `token.json`. |
| 96 | +- **save_refresh_tokens**: Saves refreshed tokens to `refresh_tokens.json`. |
| 97 | +- **get_refresh_tokens**: Retrieves tokens from `refresh_tokens.json`. |
| 98 | +- **validate_date**: Validates the date format. |
| 99 | +- **validate_email**: Validates the email format. |
| 100 | +- **fetch_heart_rate_data_for_date**: Fetches heart rate data for a specific date. |
| 101 | + |
| 102 | +## Example |
| 103 | + |
| 104 | +```sh |
| 105 | +# Authenticate and get tokens |
| 106 | +pyfitbit token -auth [email protected] |
| 107 | +
|
| 108 | +# Refresh tokens |
| 109 | +pyfitbit token -refresh [email protected] |
| 110 | +
|
| 111 | +# Extract intraday heart rate data for a single date |
| 112 | +pyfitbit extract intraday-heart-rate 2023-07-01 [email protected] |
| 113 | +
|
| 114 | +# Extract intraday heart rate data for a date range |
| 115 | +pyfitbit extract intraday-heart-rate 2023-07-01 2023-07-07 [email protected] |
| 116 | +``` |
| 117 | + |
| 118 | +## License |
| 119 | +This project is licensed under the MIT License. |
0 commit comments