Once again, Python proves itself to be the shit. The proofs of the kids' portraits is online, but not as really truly images. Instead, they're backgrounds for a div, with copyright/proof text overlaid on top, so you can't just right-click and save the image. However, you can get to the files directly (viewing the page source gives the URL), and they've very kindly listed the filenames for each picture on the thumbnails page.
I did everything from the command prompt of the Python interpreter.
- Import the modules I need:
urllibfrom the standard libraries for retrieving the proofs from the web, and the Python Imaging Library for resizing them. - Make a list of out of the image names:
files=['img001.jpg', 'img002.jpg'] - Iterate over the list and use
urllib.urlretrieve()along with the base path to suck down the files onto disk:files=[urllib.urlretrieve(base+file, file) for file in files] - Iterate over the list again to resize the images:
for file in files: im=Image.open(file) im.resize(tuple([2*ele for ele in im.size])).save(file)(note that Textile2 won't let me keep my line breaks here, so watch out) - Generate the list items for the HTML:
for file in files: print '<li><a onclick="return showPic(this)" href="%s">%s</a></li>' % (file, file) - Use A List Apart's recent and very hoopy Javascript image gallery, modified to use the first image in the list as the "seeder" instead of a spacer gif.
- Use A List Apart's not-so-recent but still hoopy pipe-delimited inline list
This was dead-easy to do. Everything just worked like it was supposed to, with no fuss. I think I should replace the gallery script on the Collier Heights photo tour with something like this. Much easier to maintain, and I bet I could modify the script to still use the Previous and Next links. Although one thing to think about is that the photo tour is much more accessible now than it would be with the script, since it uses navigation links. The script also doesn't let me cue the browser as to the image size, but I don't know if that's so important. The main trade-off looks like maintainability (one page for the script, no matter how many pictures are in the tour) versus accessibility.
I've also been using Python at work, to suck CSV files into Oracle using cx_Oracle. Since I've only just upgraded to Python 2.3, I've moved from using David Cole's CSV module to using the library csv module. My one gripe with the built-in is that it's a little harder to skip the header line. I think that the difference is that the library module uses an iterator, and Cole's module uses a sequence. Maybe I should stick with Cole's, but I don't know how I'd avoid namespace conflicts with the library module.
Bruce Eckel has said that Python's tagline should be "Python: It thinks like you do". I think he's right.
Tags: No Comments
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.