Skip to content

Commit

Permalink
created some rough idea files and setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
leohemsted committed Jun 7, 2015
1 parent b45f776 commit 77fb2cc
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 56 deletions.
58 changes: 2 additions & 56 deletions .gitignore
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
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include gfit2mfp *.py
Empty file added gfit2mfp/__init__.py
Empty file.
54 changes: 54 additions & 0 deletions gfit2mfp/main.py
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)
4 changes: 4 additions & 0 deletions gfit2mfp/settings.py
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'

16 changes: 16 additions & 0 deletions setup.py
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',
]
)

0 comments on commit 77fb2cc

Please sign in to comment.