-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetVancouverOlympicsPhotos.rb
executable file
·50 lines (44 loc) · 1.87 KB
/
getVancouverOlympicsPhotos.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
#!/usr/bin/env ruby
require 'json'
require 'pp'
require 'time'
require 'date'
require 'mongo'
require 'uri'
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
FLICKR_DB = ENV["FLICKR_DB"]
raise(StandardError,"Set Mongo flickr database name in ENV: 'FLICKR_DB'") if !FLICKR_DB
FLICKR_USER = ENV["FLICKR_USER"]
raise(StandardError,"Set flickr user name in ENV: 'FLICKR_USER'") if !FLICKR_USER
db = Mongo::Connection.new(MONGO_HOST, MONGO_PORT.to_i).db(FLICKR_DB)
if MONGO_USER
auth = db.authenticate(MONGO_USER, MONGO_PASSWORD)
if !auth
raise(StandardError, "Couldn't authenticate, exiting")
exit
end
end
photosColl = db.collection("photos")
query = {}
metrics_start = Time.local(2010, "feb", 1, 0,0,0)
metrics_stop = Time.local(2010, "feb", 28,23,59,59)
metrics_stop += 1
query = {"datetaken" => {"$gte" => metrics_start, "$lt" => metrics_stop}}
query["woeid"] = {"$in" => ["26332807","26332813","9807","23404908",
"55855889","26332808","26332809","23404939","23404944","26332811","23405256",
"23404951","23404960","55855888","23405264","55855887","26332812","23404977",
"23404979","55855620","55998921","23405270","23405266","23404994"]
}
photosColl.find(query,
:fields => ["woeid", "latitude", "longitude", "datetaken"]
).sort([["datetaken", Mongo::ASCENDING]]).each do |p|
printf("[%s,%s],\n", p["latitude"].to_s, p["longitude"].to_s)
# $stderr.printf("photo datetaken:%s, lat:%s, lon:%s\n", p["datetaken"].to_s, p["latitude"].to_s, p["longitude"].to_s)
end