Archive for the ‘photography’ tag
Storage devices

Originally uploaded by iandexter.
Playing around with my phone cam’s white balance. Crappy, but acceptable.
Downloading Flickr photos, part 2
I made several improvements in the previous script:
#!/usr/bin/python import flickr import urllib import time import re flickr.API_KEY = 'Flick API goes here' print "Registered using API key" user = flickr.people_findByUsername(u'username') print "Found user %s - username" % user.id try: photos = flickr.people_getPublicPhotos(user.id, 500) print "Found the photos" total = 0 for photo in photos: p = flickr.Photo(photo.id) title = re.sub('\s+', '-', p.title) title = re.sub('[^-\w]', '', title) title = "%s_%s" % (title, p.datetaken.split()[0]) for s in p.getSizes(): url = s['source'] photoFile = "%s_%s" % (title, url.split("/")[4]) data = urllib.urlretrieve(url, photoFile) total = total + 1 print "Retrieving %s ..." % photoFile time.sleep(1) except AttributeError: exit print "%s photos retrieved." % total
Python is pretty simple, once you get the hang of it. It also helps that the source for flickr.py is open — I got to fetch some more info regarding the photos I’m downloading, thus incorporating them in the code.
The code could use some more improvement, though: I should have opted for the Flickr error code (flickr.FlickrError) instead of AttributeError. The regex can certainly use more trimming. Perhaps I can save the photo information in a database instead of glomming them in the filename (so I can include tags, group and set memberships, etc.),
This should be elementary to Python devs out there, but for me, it’s just a hobby. ![]()
Downloading Flickr photos
Flickr Leech is a cool web app. It displays all Flickr photos, including those already rendered invisible because of the 200-photo limit in free accounts. But I need more: I want to download these photos for backup.
After looking around, I found several tools that does the job. They didn’t quite work for me, so I decided to hack my own.
Using the Flickr API and a Python wrapper, I came up with the following:
- Get flickr.py and manually add it to the host Python library.
- Get an API key from Flickr.
- Write the script:
#!/usr/bin/python import flickr import urllib flickr.API_KEY = 'API key goes here' user = flickr.people_findByUsername(u'username') photos = flickr.people_getPublicPhotos(user.id, 500) total = 0 for photo in photos: photoURL = "http://static.flickr.com/%s/%s_%s_o.jpg" % (photo.server, photo.id, photo.secret) photoFile = "%s_%s.jpg" % (photo.title, photo.id) data = urllib.urlretrieve(photoURL, photoFile) total = total + 1 print "Downloading %s" % photoFile print "Done with %s photos." % total
- Make the script executable, create a directory where to download files, and execute the script from there.
- Rinse, dry, press.
I know, the script is very rudimentary. It’s my first Python script, and it needs a lot of work: there’s no exception-handling for one. But it worked perfectly for me.
Leeching off Flickr
Here’s a great way of displaying Flickr photos in a bunch. And for a spendthrift like me who doesn’t have a Pro account (yet), this is a nifty method of retrieving that long-gone photo that has been bumped off the 200-photo display limit for the free accounts.
Via Lifehacker.
Racy flora
What I did on Valentine’s Day…. Originally uploaded by Nex Ninek.
From a Flickr photoset. View the rest of the photoset.

