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.

Tagged with:
 

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

  1. Siddhu Warrier says:

    Nice!

  2. Holger Dürer says:

    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?

  3. Roman Kirillov says:

    @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.

  4. Roman Kirillov says:

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

  5. Roman Kirillov says:

    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.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">