Created
November 18, 2010 18:33
-
-
Save nakajima/705389 to your computer and use it in GitHub Desktop.
Prints advertising slogans to the command line. Awesome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# USAGE | |
# | |
# Install the nokogiri gem by running (it might need sudo): | |
# | |
# $ gem install nokogiri | |
# | |
# Get a random slogan: | |
# | |
# $ slogan | |
# | |
# Get a slogan for a word or phrase | |
# | |
# $ slogan "boom boom" | |
# | |
# You can pass -n a command line option to get multiple slogans: | |
# | |
# $ slogan "boom boom" -n 10 | |
# | |
# That'll get you 10 slogans. Boom. | |
require 'rubygems' | |
require 'open-uri' | |
begin | |
require 'nokogiri' | |
rescue LoadError | |
abort "Oops! You need to install the nokogiri gem:\n\n $ gem install nokogiri\n\n" | |
end | |
# Screw optparse. I got this. | |
if i = ARGV.index('-n') | |
count = ARGV[i+1] | |
ARGV.delete(count) | |
ARGV.delete('-n') | |
else | |
count = 1 | |
end | |
phrase = ARGV.join('+').gsub(/\s/, '+') | |
count.to_i.times do | |
doc = Nokogiri(open('http://thesurrealist.co.uk/slogan.cgi?word=' + phrase)) | |
puts doc.at('.h1wrap h1 a').text | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment