Skip to content

Instantly share code, notes, and snippets.

@hrp
Created April 30, 2010 16:20
Show Gist options
  • Save hrp/385422 to your computer and use it in GitHub Desktop.
Save hrp/385422 to your computer and use it in GitHub Desktop.
SF Weekly Happy Hours on a Map
#!/usr/bin/ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'geokit'
url = 'http://www.sfweekly.com/content/printVersion/1956736'
doc = Hpricot open url
places = []
doc.search('p b').each do |place|
name = place.parent.search('b').inner_text
location = place.parent.search('i').first.inner_text[/[^(]+/].strip
phone = place.parent.search('i').first.inner_text[/\d{3}-\d{4}/].strip
link = place.parent.search('i a').first[:href] rescue nil
ll = Geokit::Geocoders::YahooGeocoder.geocode("#{location}, San Francisco, CA").ll
lat, lon = ll.split(',')[0],ll.split(',')[1]
# happhours
# place.parent.search('i').each do |happyhour|
# happyhour.inner_text[/\d[:&-]/]
# en
happyhours, description = nil
# puts "#{name},#{location},#{phone},#{link},#{happyhours},#{ll}"
places << {:name => name, :ll => ll, :lat => lat, :lon => lon}
end
p places
class Place
attr_accessor :name, :location, :phone, :link, :happyhours, :description
def initialize
# raise "not hash" unless hash.respond_to?(:each_key)
# hash.each do |k,v|
# self.instance_variable_set("@#{k}", v)
# self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")})
# self.class.send(:define_method, "#{k}=", proc { |v|
# self.instance_variable_set("@#{k}", v)
# })
# end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment