Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
require 'withings'
require 'time'
include Withings
Withings.consumer_key = <CONSUMER KEY>
Withings.consumer_secret = <CONSUMER SECRET>
user_id = <USER ID>
access_token = <ACCESS TOKEN>
access_token_secret = <ACCESS_TOKEN_SECRET>
user = User.authenticate(user_id, access_token, access_token_secret)
out_file = File.open("activities.csv", "a")
out_file.puts("date,weekday,steps,distance,calories,elevation,soft,moderate,intense")
res = user.get_activities(:startdateymd => '2014-07-01', :enddateymd => '2014-09-15')
res['activities'].each do |r|
weekday = Time.parse(r['date']).strftime('%w')
out_file.puts("#{r['date']},#{weekday},#{r['steps']},#{r['distance']},#{r['calories']},#{r['elevation']},#{r['soft']},#{r['moderate']},#{r['intense']}")
end
out_file.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment