begin process at 2012 05 24 05:03:56
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Réseau & internet

 > RÉCUPÉRER LES PHOTOS D'UN ALBUM SUR ZOOOMR

RÉCUPÉRER LES PHOTOS D'UN ALBUM SUR ZOOOMR


 Information sur la source

 Description

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

  • __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()
__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 ...


 Sources du même auteur

Source avec Zip LIRE DES FICHIERS PCAP
Source avec Zip FTP AVEC PYTHON
VÉRIFIER SES MAILS AVEC TUX DROID
Source avec Zip PIERRE FEUILLE CISEAUX AVEC TUX DROID
Source avec Zip HIDS EN PYTHON

 Sources de la même categorie

SOCKET MULTITHREAD SIMPLE par Guillamue06
TRANSFERT DE FICHIER PAR SOCKET par Guillamue06
Source avec une capture AUTO-FOLLOW/UNFOLLOW [TWITTER] EN [PERL] UTILISANT NET::TWIT... par GeroXXXX
Source avec Zip PINGEUR RÉSEAU par jeanbleo44
Source avec Zip Source avec une capture LISTING ET LOGS DES CONNEXIONS ET DECONNEXIONS DE MACHINES Q... par saigneurdushi

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture JEU DU DÉMINEUR par KimbleMandel
Source avec Zip LIRE ET PARSER UN FICHIER NZB ( XML AVEC SAX) par azalsup
Source avec Zip CLIENT/SERVEUR XMLRPC par balisong1
Source avec Zip Source avec une capture PHOTOPUZZLE (VERSION 1.1) par Nwonknu

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

XML Dom [ par MHI ] Voici un exemple et une petite explication sympathique que j'ai trouvé sure developpez.com traitant de XML et de l'API DOM :'Utilisation de l'API DOM API Win32 avec python????? [ par Uims ] Bonjour ami programmeur, Je viens de commencer la programmation en python. Je ne trouve déja pas de IDE (wxPython ne fonctionne pas (erreur a la python debutant [ par supai ] print "début" # début procédure from os import chdir chdir("/Volumes/GERTEX/_test/") import shutil, string, re obfic = open("taglist.xml","r") # Le Tkinter et changment d'image [ par vega95 ] Bonjour,j'ai écrit le code suivant pour afficher une image à l'accueil en attendant le début du programme. Une fois le bouton b1 enfoncé, je voudrais python et Speech API 5.1 [ par brennal ] Bonjour, J'utilise python et son extension PyWin32 pour développer avec l'API Speech 5.1 de windows XP (pack 2). J'ai installé et définit par défaut Importer la Base de registre windows en xml pour la réutiliser en xml. [ par Psychokenshin ] Bonjour à tous, Je cherche donc à exporter ma base de registre windows dans un fichier xml et ce de façon à pouvoir l'utiliser facilement dans un dic Ouvrir une image au format pgm ASCII [ par PunkFloyd91 ] Bonjour, petit soucis cela fait plusieurs jours que je cherche sur internet et je ne trouve pas comment ouvrir une image dans le format pgm en ASCII v


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,669 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales