Skip to content

Instantly share code, notes, and snippets.

@jjulian
Last active December 16, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjulian/5448289 to your computer and use it in GitHub Desktop.
Save jjulian/5448289 to your computer and use it in GitHub Desktop.
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
Copy link

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