Skip to content

Instantly share code, notes, and snippets.

@parolkar
Created August 25, 2009 17:45
Show Gist options
  • Save parolkar/174868 to your computer and use it in GitHub Desktop.
Save parolkar/174868 to your computer and use it in GitHub Desktop.
#!/bin/sh
########
#
# Ruby Oneliner FUN !
#
# Cool, on http://science.howstuffworks.com/quote1463.htm
# there are 1982 quotes - lets get them and stuff them into a CSV file d(^^)p
#
# Dependencies: ruby, hpricot, open-uri, zsh (or whatever)
#
# Disclaimer: If your machine explodes or whatever you can't hold me responsible.
#
# Licence: GPL, (c) 2009, Bjoern Rennhak
#
#
# Script executes writes to "Quotes_-_From_How_Stuff_works.csv" file and shows it also on the screen for reading
# conventience ;)
#
# If you copy&paste make sure to take away the linebreaks - this is a oneliner ok?
#
##############
ruby -rhpricot -ropen-uri -e "min, max = 1, 1982; File.open( 'Quotes_-_From_How_Stuff_works.csv', 'w') { |f| s1 = 'index, author, quote'; f.write(s1.to_s+\"\n\"); puts s1; min.upto(max) { |n
| t = Hpricot(open(\"http://science.howstuffworks.com/quote#{n}.htm?author=0\")); a = t.search('//div[@class=author]').innerHTML.to_s.gsub('—','').strip; q = Hpricot( t.search('//div[@class=quote]').innerHTML.to_s ).at('im
g').next.next.next.to_s.strip; s2 = \"#{n}, \'#{a}\', \'#{q}\'\" ; f.write(s2.to_s+\"\n\"); puts s2 ; sleep 1 if(n%10) } } "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment