Ce petit script permet de récupérer simplement toutes les photos d'un album sur le site Zooomr. Il utilise les API de Zooomr censées être interopérable avec Flickr.
Source / Exemple :
__author__ = "Cedric Bonhomme"
__date__ = "$Date: 2008/07/29 18:22 $"
__copyright__ = "Copyright (c) 2008 Cedric Bonhomme"
__license__ = "GPL 3"
class Photo(object):
"""Represent a photo.
"""
def __init__(self):
self.title = ""
self.secret = ""
self.owner = ""
self.id = ""
def getPhoto(photoset = "35479"):
"""Donwload all the photographs from the _photoset_ set.
"""
from xml.dom.minidom import parse
print "Creating statement..."
liste = []
method = "zooomr.photosets.getPhotos"
photoset_id = photoset
apiApps = "http://api.zooomr.com/services/rest/?method=" + method + "&api_key=" + myAPIkey + "&photoset_id=" + photoset
print apiApps
print 'Getting info...'
doc = parse(urllib2.urlopen(apiApps))
print 'Parsing XML file...'
for tag in doc.getElementsByTagName("rsp"):
for foto in tag.getElementsByTagName("photo"):
if foto.getAttribute("isprimary") == "0": # the primary photo occurs twice
p = photo.Photo()
p.title = foto.getAttribute("title")
p.secret = foto.getAttribute("secret")
p.owner = foto.getAttribute("owner")
p.id = foto.getAttribute("id")
liste.append(p)
if liste: # if the set is not empty
print "Downloading " + str(len(liste)) + " photographs"
for photographs in liste:
image_url = "http://static.zooomr.com/images/" + photographs.id + "_" + photographs.secret + "_b.jpg"
# Download the image:
print 'Downloading %s' % image_url
filein = urllib2.urlopen(image_url)
try:
image = filein.read()
except MemoryError:
return None
filein.close()
# Checking
if len(image) == 0:
print "Zooomr return none."
return None
if len(image) >= 5000000:
print "Photograph too big."
return None
if image.startswith('5426276'):
print "Photograph not available."
return None
# Save to disk
filename = photographs.title + '-' + photographs.id
fileout = open(filename,'w+b')
fileout.write(image)
fileout.close()
print "Photograph " + photographs.title + " downloaded."
print
print "Done."
else:
print "Empty set."
if __name__ == '__main__':
myAPIkey = None
while not myAPIkey:
myAPIkey = raw_input("Your API Key:\n")
if myAPIkey:
break
getPhoto()
Conclusion :
Voilà, si vous avez des commentaires ...
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.