Skip to content

Instantly share code, notes, and snippets.

@danielhum
Last active December 10, 2015 01:18
Show Gist options
  • Save danielhum/4356954 to your computer and use it in GitHub Desktop.
Save danielhum/4356954 to your computer and use it in GitHub Desktop.
based on http://berzniz.com/post/15975242632/export-your-appannie-data . see blog post for how to get your account id
#!/usr/bin/env ruby
APPANNIE_USERNAME = "your_appannie_username"
APPANNIE_PASSWORD = "your_appannie_password"
APPANNIE_ACCOUNT_ID = "your_appannie_account_id"
start_date = 1.year.ago.strftime("%Y-%m-%d")
end_date = Date.today.strftime("%Y-%m-%d")
require 'mechanize'
agent = Mechanize.new
page = agent.get("https://www.appannie.com/account/login/")
# login
form = page.form_with(:action => "/account/login/")
username_field = form.field_with(:name => "username")
username_field.value = APPANNIE_USERNAME
password_field = form.field_with(:name => "password")
password_field.value = APPANNIE_PASSWORD
form.submit
# get stats
agent.get("https://www.appannie.com//sales/units_data/?account_id=#{APPANNIE_ACCOUNT_ID}" +
"&type=units&s=#{start_date}&e=#{end_date}")
data_string = agent.page.parser.xpath("html/body/p/text()[1]").text
data = MultiJson.load(data_string.scan(/\[{\"data\": .*/).first).first["data"]
# cleanup the data
(0..data.count-1).each do |i|
data[i].delete(nil)
end
data.each do |d|
# do what you want with the data
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment