Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Scrape the beer list from your favorite bar in Baltimore. Built at OSHN April 23, 2013
#!/usr/bin/env ruby
# encoding: UTF-8
require 'rubygems'
require 'mechanize'
require 'optparse'
OptionParser.new do |opts|
opts.banner = "Usage: #{__FILE__} [options]\nGet a beer list from your favorite bar."
opts.on("-s", "--site SITE", "Where are you?") do |s|
$site = s
end
end.parse!
exit 2 unless $site
def scrub(s)
s = s.strip.gsub(/\s+/, ' ')
s.size > 0 ? s : nil
end
def maxs(a)
page = a.get('http://www.maxs.com/')
nodes = page / '#sidebar .p7TPcontent li'
nodes.map { |node| scrub(node.content) }.compact
end
def mahaffeys(a)
page = a.get('http://www.mahaffeyspub.com/beer/beers_in_stock.php')
lines = (page / 'body').to_s
lines.split("\n").map do |line|
m = line.match(/\((?:C|D)\)\s*(.+)/)
m && scrub(m[1].chomp)
end.compact
end
def hudson_st(a)
page = a.get('http://www.hudsonstreetstackhouse.com/food-drink-menus/daily-drafts.html')
nodes = page / '#maincol p strong'
nodes.map { |node| scrub(node.content) }.compact.uniq
end
a = Mechanize.new { |agent|
agent.user_agent_alias = 'Mac Safari'
}
beers = send($site.to_sym, a)
puts beers.join("\n")
@ngauthier

Why isn't this a hypermedia api?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.