Skip to content

Instantly share code, notes, and snippets.

@hongo35
Created September 20, 2014 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hongo35/b48805bd5513093a8973 to your computer and use it in GitHub Desktop.
Save hongo35/b48805bd5513093a8973 to your computer and use it in GitHub Desktop.
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