Create a gist now

Instantly share code, notes, and snippets.

@jjulian /beers.rb
Last active Dec 16, 2015

What would you like to do?
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' 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
exit 2 unless $site
def scrub(s)
s = s.strip.gsub(/\s+/, ' ')
s.size > 0 ? s : nil
def maxs(a)
page = a.get('')
nodes = page / '#sidebar .p7TPcontent li' { |node| scrub(node.content) }.compact
def mahaffeys(a)
page = a.get('')
lines = (page / 'body').to_s
lines.split("\n").map do |line|
m = line.match(/\((?:C|D)\)\s*(.+)/)
m && scrub(m[1].chomp)
def hudson_st(a)
page = a.get('')
nodes = page / '#maincol p strong' { |node| scrub(node.content) }.compact.uniq
a = { |agent|
agent.user_agent_alias = 'Mac Safari'
beers = send($site.to_sym, a)
puts beers.join("\n")

This comment has been minimized.

Show comment Hide comment

ngauthier Apr 23, 2013

Why isn't this a hypermedia api?

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