Jon Aquino's Mental Garden

Engineering beautiful software jon aquino labs | personal blog

Sunday, March 06, 2005

Ruby-Cygwin script to download links to PDA

Here's a little Ruby script I wrote to download my links to a directory which I have sync'd to my PDA. It grabs the links marked with a "read-review-mobile" tag. It only grabs each link once - that way I can delete pages from my PDA, and they won't get replaced.

puts `touch delicious.txt` # Create if necessary [Jon Aquino 2005-03-04]
old_urls = File.readlines("delicious.txt").each {|line|line.strip!}
`lynx -source "" | grep delLink`.split("\n").each {|line|
line =~ /.*href="(.*)">(.*)<.a>.*/
url = $1.strip
title = $2.strip
puts "#{title}\n#{url}"
if old_urls.include?(url) then
puts "SKIPPED"
puts `lynx -source "#{url}" > "#{title.gsub(/[^A-Za-z0-9]/, " ").gsub(/ +/, " ")[0..30]+".html"}"`
puts `mv *.html "C:\\Documents and Settings\\Jon\\My Documents\\X30 Storage Card\\Delicious\\"`
puts `echo #{url.gsub(/&/, "^&")} >> delicious.txt`


Post a Comment

<< Home