flickrpy + 30 lines of code = poor man's Flickr Backup solution

It uses somewhat buggy but excellent flickrpy module by James Clarke — works well for me after some small adjustments:

def main():
    flickr.API_KEY = constants.API_KEY
    flickr.API_SECRET = constants.API_SECRET

    u = flickr.User(id = '92002612@N00')
    sets = u.getPhotosets()

    for ps in sets:
        name = ps.title
        name = name.replace('"', "'").replace("/", "_")

        folderName = "/Users/kirillov/Pictures/Flickr/%s" % name
        if os.path.exists(folderName):
            print("Path exists, skipping: %s" % folderName )
            continue

        photos = ps.getPhotos()

        os.mkdir(folderName)
        i = 0
        for i,p in enumerate(photos):
            src = p.getSizes()[-1]['source']
            photoname = p.getTitle().replace("/", "_")

            fname = '/Users/kirillov/Pictures/Flickr/%s/%s-%d.jpg' % (name, photoname, i)
            data = u2.urlopen(src).read()
            open(fname, 'w').write(data)

            print('%s => "/Users/kirillov/Pictures/Flickr/%s/%s-%d.jpg"' % (src,name, photoname, i))

Upd: fixed and updated version posted.

Posted in: Uncategorized

Tags: , ,



This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

5 Comments

rssComments RSS transmitTrackBack Identifier URI


Nice!

Comment by Siddhu Warrier on January 15, 2010 12:13 pm


Do you know about enumerate?Get rid of the ‘i’ variable and just sayfor i, p in enumerate(photos):Are you sure you won’t have a slash (‘/’) in your names that would need replacing?

Comment by Holger Dürer on January 15, 2010 12:31 pm


@Holger: good point about slashes. Not likely but still. W.r.t to enumerate — nope, didn’t think about it :-) anyway let’s wait till it fails, then I will write a work around for not re-downloading already downloaded sets, escaping slashes and fixing whatever-problem-it-will-fail-because-of.

Comment by Roman Kirillov on January 15, 2010 12:34 pm


Finally it's failed – slash in the name, as it was expected. Fixing the script… 

Comment by Roman Kirillov on January 15, 2010 1:56 pm


Yeah, script is fixed and running on :-) still buggy probably, but at least file name “????? ???????? ? ?????????? ? Mac OS X / Apple / ?????????.jpg” doesn’t confuse it anymore.

Comment by Roman Kirillov on January 15, 2010 2:02 pm

addLeave a comment