Skip to content

Instantly share code, notes, and snippets.

@trtg
Created June 3, 2012 09:21
Show Gist options
  • Save trtg/2862723 to your computer and use it in GitHub Desktop.
Save trtg/2862723 to your computer and use it in GitHub Desktop.
A basic example of how to use pywithings
from withings import *
import matplotlib.pyplot as plt #for plotting weights
from datetime import datetime
from pandas import *
#-----------------------------------
#get your consumer key and secret after registering
#as a developer here: https://oauth.withings.com/en/partner/add
consumer_key='your_consumer_key_here_1111111111111111111111111111111111111111'
consumer_secret='your_consumer_secret_here_1111111111111111111111111111111111111111111'
#the first argument here is the email address you used to register
#for a Withings developer account
wobj=Withings('your_registered_email_address@example.com',consumer_key,consumer_secret)
(dates,weights)=wobj.get_weights()
print "You have ",len(weights)," weight measurements recorded"
#pandas allows us to build a timeseries object which will display
#dates along the x-axis when plotted and can have rolling window
#functions applied to it, like rolling_mean,rolling_median,rolling_std,etc.
rdates=[datetime.fromtimestamp(i) for i in dates]
ts=Series(weights,index=rdates)
#the marker='o' option will put a dot at each measurement point
#which, if you mouse-over will display the value
ts.plot(marker='o',color='b')
plt.ylabel('Weight(lbs)')
#this will overlay a smoothed curve which suggests the trend
#of the underlying data
rolling_mean(ts,len(weights)/float(7)).plot(color='r',linewidth='3')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment