8 @@url = 'http://www.guiaoleo.com.ar/list.php'
9 @@iconv = Iconv.new('UTF-8','ISO-8859-1')
12 def fetch_page(page_num)
13 puts 'Fetching page ' + page_num.to_s
14 res = Net::HTTP.get(URI.parse(@@url+Util.build_uri_params({
16 'navby' => 'multiply',
17 # For now, hardcode search to Capital only, since addresses returned in list don't include city
18 'zona' => '10,15,31,5,30,19,2,22,32,13,18,7,20,3,23,55,6,1,24,25,4,8,17,12,16,9'
20 res = @@iconv.iconv(res)
22 # Parse the list of restaurants. Currently parsed elements:
23 # - name, address, detail URL
25 res.scan(/detail.php.*?\/tr/).each do |row|
28 restaurant['url'] = 'http://www.guiaoleo.com.ar/detail.php?ID=' + $~[1]
30 restaurant['name'] = $~[1]
31 cols = row.scan(/<td>.*?<\/td>/)
34 puts "Failed parsing. COL = [" + cols[2] + "] from ROW = [" + row + "]"
36 restaurant['address'] = $~[1] + ", capital federal, argentina"
38 restaurants.push(restaurant)
41 # Parse the total number of pages
42 @pages=res.scan(/Page=(\d+)/).inject(0) { |max,n| n[0].to_i>max ? n[0].to_i : max }