2008-11-10 14:44:46 Obama Headline Grabber in F-Script
There is a nice page of newspaper headlines from around the world collected here. They're only JPEGs and not PDFs, but it's free, so I'll not complain too loudly. Anyway, if you already have fscript installed on your system and want to grab all the images, this is a quick script to do so:

( fscript )
  1  url := NSURL URLWithString:'http://obama2008.s3.amazonaws.com/headlines.html'.
2 html := NSString stringWithContentsOfURL:url encoding:1 error:nil.
3 imgPrefix := 'http://www.newseum.org.nyud.net/media/dfp/jpg5/lg/'.
4 parts := html componentsSeparatedByString:imgPrefix.
5 imageChunks := ((parts count -1) iota) +1.
6 [ :chunk |
7 imageName := (((parts at:chunk) componentsSeparatedByString:'.jpg') at:0) ++ '.jpg'.
8 imageAddress := imgPrefix ++ imageName.
9 data := NSData dataWithContentsOfURL:(NSURL URLWithString:imageAddress).
10 sys execNoOutput:'sleep' args:{'10'}.
11 data writeToFile:imageName atomically:NO.
12 ] value:@imageChunks.

If you're dropping straight down to the commandline to do this, create your own folder first and then cd into that directory. The one hitch here may be that the block ( [ :chunk | … ] value:@imageChunks. ) may needsto be on one line for some reason. Or perhaps it's a glitch with the fscript build I have currently. (The sleep line was added to make sure the images had time to download, though i'm not sure it's needed. Seems polite if nothing else.)

Of course, you could do this all just as beautifully in Python or Ruby, etc, but there it is. Contribute more version below if you want.
Leave a comment