-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_firefox_desktop_words_by_start_stop_date.rb
executable file
·55 lines (52 loc) · 1.81 KB
/
get_firefox_desktop_words_by_start_stop_date.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env ruby
require 'rubygems'
require 'pp'
require 'json'
require 'time'
require 'date'
require 'mongo'
Mongo::Logger.logger.level = ::Logger::FATAL # http://stackoverflow.com/questions/30292100/how-can-i-disable-mongodb-log-messages-in-console
MONGO_HOST = ENV["MONGO_HOST"]
raise(StandardError,"Set Mongo hostname in ENV: 'MONGO_HOST'") if !MONGO_HOST
MONGO_PORT = ENV["MONGO_PORT"]
raise(StandardError,"Set Mongo port in ENV: 'MONGO_PORT'") if !MONGO_PORT
MONGO_USER = ENV["MONGO_USER"]
# raise(StandardError,"Set Mongo user in ENV: 'MONGO_USER'") if !MONGO_USER
MONGO_PASSWORD = ENV["MONGO_PASSWORD"]
# raise(StandardError,"Set Mongo user in ENV: 'MONGO_PASSWORD'") if !MONGO_PASSWORD
QUESTIONS_DB = ENV["QUESTIONS_DB"]
raise(StandardError,\
"Set Mongo instagram database name in ENV: 'QUESTIONS_DB'") \
if !QUESTIONS_DB
db = Mongo::Client.new([MONGO_HOST], :database => QUESTIONS_DB)
if MONGO_USER
auth = db.authenticate(MONGO_USER, MONGO_PASSWORD)
if !auth
raise(StandardError, "Couldn't authenticate, exiting")
exit
end
end
questionsColl = db[:questions]
if ARGV.length < 6
puts "usage: #{$0} yyyy mm dd yyyy mmm dd -v"
exit
end
MIN_DATE = Time.local(ARGV[0].to_i, ARGV[1].to_i, ARGV[2].to_i, 0, 0) # may want Time.utc if you don't want local time
MAX_DATE = Time.local(ARGV[3].to_i, ARGV[4].to_i, ARGV[5].to_i, 23, 59) # may want Time.utc if you don't want local time
questionsColl.find(:created =>
{
:$gte => MIN_DATE,
:$lte => MAX_DATE },
:product_id => 1 # Firefox desktop is product id 1
).projection(
{
"id" => 1,
"created" => 1,
"title" => 1,
"content" => 1,
"product_id" => 1
}).each do |q|
PP::pp(q, $stderr)
puts q["title"].split(' ')
puts q["content"].split(' ')
end