Tag Archive for 'flickr'

2007 in pictures

Cover-flow style, courtesy of MooFlow tools. The photos were compiled from Flickr.

2007 in pictures

I was attempting to automate the process ala-fd’s Flickr toys, what with the Flickr API’s fantastic use of JSON responses (no need for server-side nor cross-site xHTTP requests). Alas, my days were packed. But I’m getting the hang of it. I’m relearning JavaScript along the way (I could actually rebuild a DOM tree from the JSON response, cool). One thing that would have made my coding easier: an API wrapper for JavaScript.

Anyway, enjoy.

Kudos to Naraoya and ATIS547 for the borrowed pics.

Work in progress: 2007 in pictures

UPDATE: It’s finally up, my review of 2007 in pictures, cover-flow style.

I’m building up a review of 2007, using Flickr photos. Nothing spectacular — just a retrospective tool for me. We have had many blessings this year, and what better way to reminisce than through pictures. For now, I’m collecting photos from various sources, one of which is provided by Flickr:

Flickr calendar

I’m famous

Sort of.

Just stumbled upon this while reviewing my Flickr account: a university lecturer in Australia used my (and a couple of other Flickr members’) mugshot in the cover for her compilation of readings. How cool is that?

Okay, so this is very ancient, but still, it’s a great ego boost. Not! But it’s nice, really.

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

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:

  1. Get flickr.py and manually add it to the host Python library.
  2. Get an API key from Flickr.
  3. 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
  4. Make the script executable, create a directory where to download files, and execute the script from there.
  5. 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.