Skip to content

Commit

Permalink
Fix cli (#7)
Browse files Browse the repository at this point in the history
* Fix cli

* Add macos pypi classifier

* Add macos pypi classifier

* Add at least one argument is required

* Add asciinema recording

* Fix typos

* Fix typos
  • Loading branch information
veerendra2 authored Dec 25, 2024
1 parent a92614d commit b42a9e1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 20 deletions.
51 changes: 41 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Fitbit CLI

[![Release](https://github.com/veerendra2/fitbit-cli/actions/workflows/release.yml/badge.svg?branch=main&event=release)](https://github.com/veerendra2/fitbit-cli/actions/workflows/release.yml) [![PyPI - Status](https://img.shields.io/pypi/status/fitbit-cli)
[![Release](https://github.com/veerendra2/fitbit-cli/actions/workflows/release.yml/badge.svg)](https://github.com/veerendra2/fitbit-cli/actions/workflows/release.yml) [![PyPI - Status](https://img.shields.io/pypi/status/fitbit-cli)
](https://pypi.org/project/fitbit-cli/) [![PyPI - Version](https://img.shields.io/pypi/v/fitbit-cli)
](https://pypi.org/project/fitbit-cli/)

Expand All @@ -9,9 +9,11 @@
Access your Fitbit data directly from your terminal 💻. View 💤 sleep logs, ❤️ heart rate, 🏋️‍♂️ activity levels, 🩸 SpO2, and more, all presented in a simple, easy-to-read table format!

<p align="center">
<img alt="Fitbit logo", width="250" src="./assets/Fitbit_Logo_White_RGB.jpg">
<img alt="Fitbit logo", width="250" src="https://raw.githubusercontent.com/veerendra2/fitbit-cli/refs/heads/main/assets/Fitbit_Logo_White_RGB.jpg">
</p>

[![asciicast](https://asciinema.org/a/696114.svg)](https://asciinema.org/a/696114)

## Supported Web APIs

> Only `GET` APIs are supported!
Expand All @@ -25,11 +27,17 @@ Access your Fitbit data directly from your terminal 💻. View 💤 sleep logs,
| [Active Zone Minutes (AZM) Time Series](https://dev.fitbit.com/build/reference/web-api/active-zone-minutes-timeseries/) ||
| [Activity](https://dev.fitbit.com/build/reference/web-api/activity/) | 👷 |

## Install
## Usage Guide

1. Install the Fitbit CLI

```bash
python -m pip install fitbit-cli
```

2. Help

```bash
fitbit-cli -h
usage: fitbit-cli [-h] [-i] [-s [DATE[,DATE]]] [-o [DATE[,DATE]]] [-e [DATE[,DATE]]] [-a [DATE[,DATE]]] [-u] [-v]

Expand All @@ -56,15 +64,38 @@ APIs:
Show user profile data
```
## Register Fitbit App
3. Register Fitbit App
1. Go to [https://dev.fitbit.com/apps](https://dev.fitbit.com/apps)
2. Click on "REGISTER AN APP" tab
3. Follow below example and register an app
1. Go to [https://dev.fitbit.com/apps](https://dev.fitbit.com/apps)
2. Click on "REGISTER AN APP" tab
3. Follow below example and register an app
<p align="left">
<img alt="Fitbit logo", width="700" src="./assets/fitbit-app-registration.png">
</p>
<p align="left">
<img alt="Fitbit logo", width="700" src="https://raw.githubusercontent.com/veerendra2/fitbit-cli/refs/heads/main/assets/fitbit-app-registration.png">
</p>
4. Run the following command to set up interactive authentication and store the Fitbit token locally
```bash
fitbit-cli --init-auth
```
For a visual guide, see the Asciinema recording below
[![asciicast](https://asciinema.org/a/696115.svg)](https://asciinema.org/a/696115)
5. Start using it 😎
```bash
$ fitbit-cli -s
Sleep Data Summary 😴
┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Date 📆 ┃ Deep Sleep 🛏 ┃ Light Sleep 💤 ┃ REM Sleep 🌙 ┃ Wake Time ⏰ ┃ Efficiency 💯 ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ 2024-12-25 │ 139 min │ 190 min │ 155 min │ 54 min │ 55% │
└────────────┴──────────────┴────────────────┴──────────────┴──────────────┴───────────────┘
```
_**NOTE: The token is valid for only 8 hours, `fitbit-cli` automatically refreshes the token when it expires.**_
## Local Development
Expand Down
2 changes: 1 addition & 1 deletion fitbit_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
fitbit_cli Module
"""

__version__ = "1.0.0"
__version__ = "1.1.0"
7 changes: 6 additions & 1 deletion fitbit_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ def parse_arguments():
help="Show fitbit-cli version",
)

return parser.parse_args()
args = parser.parse_args()

if not any(vars(args).values()):
parser.error("No arguments provided. At least one argument is required.")

return args
8 changes: 4 additions & 4 deletions fitbit_cli/fitbit_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def fitbit_init_setup():
if browser_status:
CONSOLE.print(
":satellite: Waiting for authorization... "
+ "(Check your browser or press 'Ctrl+C', authrize the app by opening the"
+ "(Check your browser or press 'Ctrl+C', authorize the app by opening the"
+ " above URL in your browser and past the redirect URL manually.)\n"
)
authorization_code = start_server()
Expand Down Expand Up @@ -166,7 +166,7 @@ def fitbit_init_setup():


def read_fitbit_token():
"""Read the Fitbit token from the file and return as a JSON object."""
"""Read Fitbit token from the file and return as a JSON object."""

try:
with open(FITBIT_TOKEN_PATH, "r", encoding="utf-8") as f:
Expand All @@ -184,15 +184,15 @@ def read_fitbit_token():


def write_fitbit_token(token_content):
"""Write the Fitbit token to the file."""
"""Write Fitbit token to the file."""

Path(FITBIT_TOKEN_PATH).parent.mkdir(parents=True, exist_ok=True)
with open(FITBIT_TOKEN_PATH, "w", encoding="utf-8") as f:
json.dump(token_content, f)


def update_fitbit_token(access_token, refresh_token):
"""Update the Fitbit token in the file."""
"""Update Fitbit token in the file."""

token_content = read_fitbit_token()
token_content["access_token"] = access_token
Expand Down
2 changes: 1 addition & 1 deletion fitbit_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def main():

args = parse_arguments()

if args.init:
if args.init_auth:
setup.fitbit_init_setup()

credentials = setup.read_fitbit_token()
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: Apache Software License",
"Natural Language :: English",
"Operating System :: MacOS",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3",
"Programming Language :: Python",
"Topic :: Utilities",
],
install_requires=[
Expand Down

0 comments on commit b42a9e1

Please sign in to comment.