Created
May 21, 2010 04:55
-
-
Save peterc/408477 to your computer and use it in GitHub Desktop.
XKCD for iPad
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
#!/bin/env ruby | |
require 'rubygems' | |
require 'open-uri' | |
require 'nokogiri' | |
doc = Nokogiri::HTML(open('http://xkcd.com/').read) | |
puts %{Content-type: text/html | |
<html><head><title>XKCD for iPad</title> | |
<style type="text/css">BODY { font-family: helvetica; font-size: 16px; text-align: center} | |
.quip { font-style: italic }</style></head><body> | |
#{doc.css("h1")} | |
<p>#{doc.css("img").detect { |x| x.attr('src') =~ /comics/ }}</p> | |
<p class="quip">#{(doc.css("img").detect { |x| x.attr('src') =~ /comics/ }).to_s[/title=\"(.*?)\"/, 1]}</p> | |
</body></html>} | |
# Totally too much in a hurry to bother figuring out the correct XPath expressions for the above shite ;-) | |
# But feel free to give it a go! |
People with headless mac servers sat on their office windowsill. cough
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool, didn't know about the attribute thing.
Also, /bin/env is fine on most Linux, which is where I did it. But, yeah, on OS X it doesn't work.. (but WTF deploys to OS X anyway..) :-)