3rocks-github
11/6/2018 - 6:18 AM

Flickr download

Flickr download

#!/usr/bin/python
import flickr_api as f
import glob
import multiprocessing
import os.path
import sys

f.set_keys(api_key = '<api_key>', api_secret = '<secret>')
f.set_auth_handler("/tmp/f.txt")

def download(p):
    fn = "/data2/weongyo/flickr/%s" % p.id
    gl = glob.glob(fn + ".*")
    if len(gl) > 0:
        print "Skipping the photo ID", p.id
    else:
        print "Downloading the photo ID", p.id
        p.save(fn)

try :
    username = sys.argv[1]
    u = f.Person.findByUserName(username)
    for i in range(3800):
        ps = u.getPhotos(per_page=10, page=i)
        pl = []
        for i, p in enumerate(ps):
            m = multiprocessing.Process(target=download, args=(p,))
            pl.append(m)
        for p in pl:
            p.start()
        for p in pl:
            p.join()
except IndexError :
    print ("usage: python show_albums.py username [access_token_file]")
    print ("Displays the list of photosets belonging to a user")