-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created some rough idea files and setup.py
- Loading branch information
1 parent
b45f776
commit 77fb2cc
Showing
6 changed files
with
77 additions
and
56 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 |
---|---|---|
@@ -1,57 +1,3 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*,cover | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
*.egg-info | ||
venv |
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 @@ | ||
recursive-include gfit2mfp *.py |
Empty file.
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,54 @@ | ||
from datetime import datetime, timedelta | ||
|
||
import httplib2 | ||
|
||
from googleapiclient.discovery import build | ||
from oauth2client.file import Storage | ||
from oauth2client.client import OAuth2WebServerFlow | ||
from oauth2client.tools import run | ||
|
||
from . import settings | ||
|
||
FIT_URL_STRING = 'https://www.googleapis.com/fitness/v1/users/{userId}/dataSources/{dataSourceId}/datasets/{datasetId}' | ||
DEV_ID = 'me' | ||
|
||
def login(): | ||
storage = Storage('user_credentials') | ||
credentials = storage.get() | ||
|
||
if credentials is None or credentials.invalid: | ||
flow = OAuth2WebServerFlow( | ||
settings.CLIENT_ID, | ||
settings.CLIENT_SECRET, | ||
settings.API_SCOPE | ||
) | ||
credentials = run(flow, storage) | ||
|
||
http = credentials.authorize(httplib2.Http()) | ||
api = build('fitness', 'v1', http=http) | ||
return api | ||
|
||
def get_time_range_str(start, end): | ||
# google accepts timestamps in nanoseconds | ||
start = int(start.timestamp() * 1e9) | ||
end = int(end.timestamp() * 1e9) | ||
return '{s}-{e}'.format(s=start, e=end) | ||
|
||
def get_fit_data(): | ||
end = datetime.now() | ||
start = end - timedelta(days=5) | ||
url = FIT_URL_STRING.format( | ||
userId='me', | ||
dataSourceId='derived:com.google.calories.expended:com.google.android.gms:from_activities', | ||
datasetId=get_time_range_str(start, end) | ||
) | ||
request = api.users(userId='me').dataSources().list() | ||
|
||
while request is not None: | ||
response = request.execute() | ||
import pdb | ||
pdb.set_trace() | ||
|
||
if __name__ == '__main__': | ||
api = login() | ||
get_fit_data(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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CLIENT_ID = '' | ||
CLIENT_SECRET = '' | ||
API_SCOPE = 'https://www.googleapis.com/auth/fitness.activity.read' | ||
|
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,16 @@ | ||
from setuptools import setup, find_packages | ||
setup( | ||
name = 'gfit2mfp', | ||
version='0.1', | ||
description='Google Fit -> My Fitness Pal', | ||
author='Leo Hemsted', | ||
author_email='[email protected]', | ||
url='https://github.com/leohemsted/gfit2mfp/', | ||
packages = find_packages(), | ||
install_requires=[ | ||
'requests>=2.7.0', | ||
'google-api-python-client>=1.4.0', | ||
'oauth2client>=1.4.6', | ||
'httplib2>=0.9.1', | ||
] | ||
) |