Created
August 1, 2012 04:40
-
-
Save fukata/3223702 to your computer and use it in GitHub Desktop.
import mongodb from treasure data.
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
#!/usr/bin/env ruby | |
require 'td' | |
require 'td-client' | |
require 'mongo' | |
WEEK = 604800 | |
cln = TreasureData::Client.new(ENV['TREASURE_DATA_API_KEY']) | |
job = cln.query('agesage', "select v['query'] as keyword, count(*) as cnt from queries where v['query'] != '' and v['time'] > unix_timestamp() - #{WEEK} group by v['query']") | |
until job.finished? | |
sleep 2 | |
job.update_status! | |
end | |
@conn = Mongo::Connection.new | |
@db = @conn['asg'] | |
@coll = @db['query_rankings'] | |
if job.success? | |
@coll.remove | |
job.result_each { |row| | |
@coll.insert({'keyword' => row[0], 'count' => row[1]}) | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment