Skip to content

Commit

Permalink
Update sample app to work with new version of the API.
Browse files Browse the repository at this point in the history
  • Loading branch information
aouyar committed Jan 26, 2013
1 parent ed0b7c8 commit 859b4e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
22 changes: 11 additions & 11 deletions samples/bottle/runkeeper_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
import optparse
import ConfigParser
import bottle
from healthgraph import RunKeeperAuthMgr, RunKeeperClient
import healthgraph
from beaker.middleware import SessionMiddleware


__author__ = "Ali Onur Uyar"
__copyright__ = "Copyright 2012, Ali Onur Uyar"
__credits__ = []
Expand Down Expand Up @@ -60,8 +59,8 @@ def index():
if sess.has_key('rk_access_token'):
bottle.redirect('/welcome')
else:
rk_auth_mgr = RunKeeperAuthMgr(conf['client_id'], conf['client_secret'],
'/'.join((conf['baseurl'], 'login',)))
rk_auth_mgr = healthgraph.AuthManager(conf['client_id'], conf['client_secret'],
'/'.join((conf['baseurl'], 'login',)))
rk_auth_uri = rk_auth_mgr.get_login_url()
rk_button_img = rk_auth_mgr.get_login_button_url('blue', 'black', 300)
return bottle.template('index.html', {'rk_button_img': rk_button_img,
Expand All @@ -72,8 +71,8 @@ def login():
sess = bottle.request.environ['beaker.session']
code = bottle.request.query.get('code')
if code is not None:
rk_auth_mgr = RunKeeperAuthMgr(conf['client_id'], conf['client_secret'],
'/'.join((conf['baseurl'], 'login',)))
rk_auth_mgr = healthgraph.AuthManager(conf['client_id'], conf['client_secret'],
'/'.join((conf['baseurl'], 'login',)))
access_token = rk_auth_mgr.get_access_token(code)
sess['rk_access_token'] = access_token
sess.save()
Expand All @@ -84,14 +83,15 @@ def welcome():
sess = bottle.request.environ['beaker.session']
access_token = sess.get('rk_access_token')
if access_token is not None:
rk = RunKeeperClient(access_token)
profile = rk.get_profile()
records = rk.get_records()
activities = rk.get_activity_list(5)
user = healthgraph.User(session=healthgraph.Session(access_token))
profile = user.get_profile()
records = user.get_records()
act_iter = user.get_fitness_activity_iter()
activities = [act_iter.next() for _ in range(5)]
return bottle.template('welcome.html',
profile=profile,
activities=activities,
records=records)
records=records.get_totals())
else:
bottle.redirect('/')

Expand Down
10 changes: 5 additions & 5 deletions samples/bottle/views/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h2>Recent Activities</h2>
<th>Distance (km)</th>
</thead>
<tbody>
%for stats in activities.get('items', []):
%for stats in activities:
<tr>
<td>{{ stats.get('start_time') }}</td>
<td>{{ stats.get('type') }}</td>
Expand All @@ -58,10 +58,10 @@ <h2>Total Distance</h2>
%for sport, stats in records.items():
<tr>
<td>{{ sport }}</td>
<td align="right">{{ '%.1f' % stats.get('THIS_WEEK', 0) }}</td>
<td align="right">{{ '%.1f' % stats.get('LAST_WEEK', 0) }}</td>
<td align="right">{{ '%.1f' % stats.get('THIS_MONTH', 0) }}</td>
<td align="right">{{ '%.1f' % stats.get('LAST_MONTH', 0) }}</td>
<td align="right">{{ '%.1f' % (stats.get('THIS_WEEK', 0) / 1000) }}</td>
<td align="right">{{ '%.1f' % (stats.get('LAST_WEEK', 0) / 1000) }}</td>
<td align="right">{{ '%.1f' % (stats.get('THIS_MONTH', 0) / 1000) }}</td>
<td align="right">{{ '%.1f' % (stats.get('LAST_MONTH', 0) / 1000) }}</td>
<td align="right">{{ '%.1f' % (stats.get('OVERALL', 0) / 1000) }}</td>
</tr>
%end
Expand Down

0 comments on commit 859b4e5

Please sign in to comment.