Skip to content

Commit 8a93a64

Browse files
committed
first commit
0 parents  commit 8a93a64

File tree

5 files changed

+478
-0
lines changed

5 files changed

+478
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Abhishek Bhardwaj
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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.

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"fitbit": {
3+
"authorize_uri": "https://www.fitbit.com/oauth2/authorize",
4+
"client_id": "your_client_id",
5+
"client_secret": "your_client_secret",
6+
"redirect_uri": "your_redirect_uri"
7+
}
8+
}

0 commit comments

Comments
 (0)