Created
November 19, 2013 07:56
-
-
Save wetzler/7541840 to your computer and use it in GitHub Desktop.
This script runs a group_by query and outputs the results to a CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'net/http' | |
require 'net/https' | |
require 'keen' | |
require 'uri' | |
require 'json' | |
require 'date' | |
# This script runs a group_by query and outputs the results to a CSV | |
#================================oOo=================================== | |
# Enter your Keen Project Info | |
Keen.project_id = "<ID>" | |
Keen.read_key = "<READ KEY>" | |
$projectID = Keen.project_id | |
$collection = "purchases" | |
timeframe = { | |
:start => "2013-11-17T06:00Z", | |
:end => "2013-11-17T07:00Z" | |
} | |
data1 = Keen.count($collection, | |
:group_by => "country", | |
:filters => [{ | |
:property_name => "Category", | |
:operator => "eq", | |
:property_value => "Shoes", | |
}], | |
:timeframe => timeframe, | |
) | |
puts "got data 1" | |
fileResults = File.open('results_'+Time.now.to_s+'.csv', 'w') | |
data1.each do |country| | |
country_name = country['country_name'] | |
count = country['result'] | |
puts "#{country_name}, #{count}" | |
fileResults.puts "#{country_name}, #{count}" | |
end | |
fileResults.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment