Skip to content

Instantly share code, notes, and snippets.

@paigeruten
Created April 19, 2013 03:06
Show Gist options
  • Save paigeruten/5417827 to your computer and use it in GitHub Desktop.
Save paigeruten/5417827 to your computer and use it in GitHub Desktop.
# whyspooler.rb
# mostly a translation of _why's OCaml script to Ruby
#
# polls whytheluckystiff.net for new printouts, converts to pdf, saves them into ./SPOOL, and prints them
#
# usage: `ruby whyspooler.rb http://whytheluckystiff.net`
#
# OS X install instructions:
# 1. `gem install open4`
# 2. download MacPCLtoPDF.zip from http://www.columbia.edu/~em36/pcltopdf.html
# 3. unzip to get MacPCLtoPDF.app
# 4. right-click on it, "Show Package Contents"
# 5. go to Contents/Resources/Files, and copy + paste "pcl6" to the directory this script is in
# 6. make sure it's executable: `chmod +x pcl6`
# 7. modify the Private_press constant below to the name of your printer
# 8. and run the script: `ruby whyspooler.rb http://whytheluckystiff.net`
#
require "open-uri"
require "open4"
`mkdir SPOOL` unless File.exists?("SPOOL")
Private_press = "HP_Deskjet_5700" # your printer name
def ppppprint_the(q, doc)
`wget -q -O #{doc} #{q}/#{doc}`
pid, stdin, stdout, stderr = Open4::popen4("./pcl6 -sDEVICE=pdfwrite -sOutputFile=#{doc}.pdf #{doc}")
while stderr.gets !~ /press <enter> to continue/
end
stdin.print "\n"
Open4::popen4("lp -d #{Private_press} #{doc}.pdf")
end
def sscan_the(thisfar, q, line)
entry = line.split("\t")
nyman = entry.first
unless thisfar.include? nyman
ppppprint_the(q, nyman)
puts "NEW #{nyman}\n"
thisfar << nyman
end
end
def hhit_the(q)
open("#{q}/index.html") do |http|
http.read
end
end
def wwhat_the(q)
thisfar = []
loop do
index = hhit_the(q)
lines = index.split("\n")
lines.each do |line|
if line =~ /^SPOOL/
sscan_the(thisfar, q, line)
end
end
sleep 120
end
end
wwhat_the(ARGV.first)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment