new test for cubito
[donde.git] / dondebatch / update.rb
blobae294659e67b8b144845cb4acff6fbd2b57a6419
1 if __FILE__ == $0
3 require 'guiaoleo.rb'
5 # Toy variable to limit the number of pages so that we can test a bit
6 max_pages = 10
8 go = Guiaoleo.new
9 i = 0
10 restaurants = []
11 restaurants.concat(go.fetch_page(i+=1)) until go.pages != nil && (i >= go.pages || i >= max_pages)
13 puts "Finished fetching, now importing"
14 # NOTE: I had to move this require to after parsing is done, otherwise it was breaking the
15 # results of the regular expressoins, particularly trying to extract the address. Don't ask me why
16 require '../dondeback/config/environment'
18 restaurants.each do |restaurant|
19   v = Venue.find_by_name(restaurant['name'])
20   if !v.nil? and v.address == restaurant['address'] then
21     puts "Skipping = [" + v.name + "]"
22   else
23     Venue.create(restaurant)
24   end
25 end
27 puts "Done importing, now geocoding"
28 require 'geocode'
30 # Find all venues that lack coordinates and geocode each of them individually
31 # TODO Look for alternative geocoders, hopefully supporting batch geocoding
32 venues = Venue.find(:all,:conditions => ["lat is null"])
33 puts "There are " + venues.length.to_s + " unmapped venues"
34 venues.each {|v| Geocode.map_venue v}
36 end