Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
252 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
language: python | ||
python: | ||
- "3.6" | ||
- "3.7" | ||
- "3.8" | ||
install: | ||
- pip install . | ||
- pip install pytest | ||
- pip install pytest-cov | ||
- pip install coveralls | ||
script: | ||
- pytest tests.py --cov=fitbit_client/ | ||
after_success: | ||
- coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2020 Audrow Nash | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include README.md LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
README | ||
====== | ||
|
||
[![PyPI version](https://badge.fury.io/py/fitbit-client.svg)](https://badge.fury.io/py/fitbit-client) | ||
[![Build Status](https://travis-ci.com/robotpt/fitbit-client.svg?branch=master)](https://travis-ci.com/robotpt/fitbit-client) | ||
[![Coverage Status](https://coveralls.io/repos/github/robotpt/fitbit-client/badge.svg?branch=master)](https://coveralls.io/github/robotpt/fitbit-client?branch=master) | ||
|
||
A Fitbit client that works from terminal to read steps data without launching a web browser or requiring that the user is signed in. | ||
|
||
Features | ||
-------- | ||
* No web sign-in is prompted when running the app | ||
* Access doesn't expire | ||
* Uses a one-time code to get the OAuth2 access token | ||
* Saves a file with the credentials that it uses by default when run | ||
* Exposes a function for generic requests to Fitbit's API | ||
* Returns intraday steps data for a specified date in a Pandas Dataframe and the datetime of the last sync | ||
|
||
Setup | ||
----- | ||
|
||
Follow the instructions [here](https://www.forkingbytes.com/blog/using-the-fitbit-api-from-a-command-line-application-in-go/) to obtain the following: | ||
* Client ID | ||
* Code | ||
* Authorization | ||
|
||
> Note that for access to intraday data, create a personal app. | ||
Then, either | ||
* Run this program and enter information when prompted | ||
* Or pass this information as function arguments | ||
|
||
You can then start making Fitbit API calls. The program supports intraday steps and the last sync time with convenience functions, and there is also a function `get_url` for making generic requests to Fitbit's API. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
from backend_fitbit_client import BackendFitbitClient | ||
from fitbit_client import FitbitClient | ||
import logging | ||
import datetime | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
|
||
fitbit_caller = BackendFitbitClient() | ||
print(fitbit_caller.get_steps()) | ||
fitbit_caller = FitbitClient() | ||
print(fitbit_caller.get_steps( | ||
datetime.date(2020, 1, 1) | ||
)) | ||
print(fitbit_caller.get_last_sync()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
requests==2.22.0 | ||
oauthlib==3.1.0 | ||
requests_oauthlib==1.3.0 | ||
pyyaml==5.3 | ||
pandas==0.25.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Note: To use the 'upload' functionality of this file, you must: | ||
# $ pipenv install twine --dev | ||
|
||
import io | ||
import os | ||
import sys | ||
from shutil import rmtree | ||
|
||
from setuptools import find_packages, setup, Command | ||
|
||
# Package meta-data. | ||
NAME = 'fitbit-client' | ||
DESCRIPTION = "Call Fitbit's web API from terminal" | ||
URL = 'https://github.com/robotpt/fitbit-client' | ||
EMAIL = 'audrow.nash@gmail.com' | ||
AUTHOR = 'Audrow Nash' | ||
REQUIRES_PYTHON = '>=3.6.0' | ||
VERSION = '0.0.2' | ||
|
||
# What packages are required for this module to be executed? | ||
REQUIRED = [ | ||
'pandas', | ||
'requests', | ||
'pyyaml>=5.1', | ||
] | ||
|
||
# What packages are optional? | ||
EXTRAS = { | ||
# 'fancy feature': ['django'], | ||
} | ||
|
||
# The rest you shouldn't have to touch too much :) | ||
# ------------------------------------------------ | ||
# Except, perhaps the License and Trove Classifiers! | ||
# If you do change the License, remember to change the Trove Classifier for that! | ||
|
||
here = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
# Import the README and use it as the long-description. | ||
# Note: this will only work if 'README.md' is present in your MANIFEST.in file! | ||
try: | ||
with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f: | ||
long_description = '\n' + f.read() | ||
except FileNotFoundError: | ||
long_description = DESCRIPTION | ||
|
||
# Load the package's __version__.py module as a dictionary. | ||
about = {} | ||
if not VERSION: | ||
project_slug = NAME.lower().replace("-", "_").replace(" ", "_") | ||
with open(os.path.join(here, project_slug, '__version__.py')) as f: | ||
exec(f.read(), about) | ||
else: | ||
about['__version__'] = VERSION | ||
|
||
|
||
class UploadCommand(Command): | ||
"""Support setup.py upload.""" | ||
|
||
description = 'Build and publish the package.' | ||
user_options = [] | ||
|
||
@staticmethod | ||
def status(s): | ||
"""Prints things in bold.""" | ||
print('\033[1m{0}\033[0m'.format(s)) | ||
|
||
def initialize_options(self): | ||
pass | ||
|
||
def finalize_options(self): | ||
pass | ||
|
||
def run(self): | ||
try: | ||
self.status('Removing previous builds…') | ||
rmtree(os.path.join(here, 'dist')) | ||
except OSError: | ||
pass | ||
|
||
self.status('Building Source and Wheel (universal) distribution…') | ||
os.system('{0} setup.py sdist bdist_wheel --universal'.format(sys.executable)) | ||
|
||
self.status('Uploading the package to PyPI via Twine…') | ||
os.system('twine upload dist/*') | ||
|
||
self.status('Pushing git tags…') | ||
os.system('git tag v{0}'.format(about['__version__'])) | ||
os.system('git push --tags') | ||
|
||
sys.exit() | ||
|
||
|
||
# Where the magic happens: | ||
setup( | ||
name=NAME, | ||
version=about['__version__'], | ||
description=DESCRIPTION, | ||
long_description=long_description, | ||
long_description_content_type='text/markdown', | ||
author=AUTHOR, | ||
author_email=EMAIL, | ||
python_requires=REQUIRES_PYTHON, | ||
url=URL, | ||
packages=find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]), | ||
# If your package is a single module, use this instead of 'packages': | ||
# py_modules=['mypackage'], | ||
|
||
# entry_points={ | ||
# 'console_scripts': ['mycli=mymodule:cli'], | ||
# }, | ||
install_requires=REQUIRED, | ||
extras_require=EXTRAS, | ||
include_package_data=True, | ||
license='MIT', | ||
classifiers=[ | ||
# Trove classifiers | ||
# Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers | ||
'License :: OSI Approved :: MIT License', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.6', | ||
'Programming Language :: Python :: Implementation :: CPython', | ||
'Programming Language :: Python :: Implementation :: PyPy' | ||
], | ||
# $ setup.py publish support. | ||
cmdclass={ | ||
'upload': UploadCommand, | ||
}, | ||
) |
Oops, something went wrong.