Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Scrape the beer list from your favorite bar in Baltimore. Built at OSHN April 23, 2013

View beers.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
#!/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")

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.