Beispiel #1
0
def download_foto_pers(persona,link_foto):
   
    ok=True
    now=datetime.datetime.now()
    new_file_dir = os.path.dirname(settings.MEDIA_ROOT+now.strftime("%Y"+os.sep+"%m"+os.sep))
    if not os.path.exists(new_file_dir):
        os.makedirs(new_file_dir)
    
    try:
        link=link_foto
        pos=link.rfind('/')
        nome_foto=link[pos+1:]
        try:
            nome_foto=nome_foto.replace('%20','_')
            name = now.strftime("%Y"+os.sep+"%m"+os.sep) + "pers" + str(persona.id) + nome_foto
            #print name
            try:
                image = urllib.URLopener()
                image.retrieve(link,settings.MEDIA_ROOT + name)
            except:
                logger_download.warning('impossibile fare download')
                logger_download.warning(link)
                image=None
            if image!=None:
                try:
                    img = Photo.objects.get(image=name)
                except:    
                    img = Photo()
                    img.name = nome_foto
                    img.image = name
                    img.caption=persona.nome + ' ' + persona.cognome 
                    img.upload_date = datetime.datetime.now()
                    img.publish_date = datetime.datetime.now()                    
                    img.save()
            
                    persona.foto.add(img)
                    persona.save()
        except:
            
            logger_download.warning('problemi con download foto')
            logger_download.warning(sys.exc_info())
            
            
    except:
        logger_download.warning(sys.exc_info())
        ok=False
Beispiel #2
0
def download_foto_episodio(episodio, link_foto):
    count = 0
    ok = True
    now = datetime.datetime.now()
    new_file_dir = os.path.dirname(settings.MEDIA_ROOT + now.strftime("%Y" + os.sep + "%m" + os.sep))
    if not os.path.exists(new_file_dir):
        os.makedirs(new_file_dir)

    try:
        link = link_foto
        pos = link.rfind("/")
        nome_foto = link[pos + 1 :]
        if nome_foto.find("no_image") == -1:
            try:
                nome_foto = nome_foto.replace("%20", "_")
                name = now.strftime("%Y" + os.sep + "%m" + os.sep) + "ep_" + str(episodio.id) + nome_foto
                image = urllib.URLopener()
                image.retrieve(link, settings.MEDIA_ROOT + name)

                try:
                    img = Photo.objects.get(image=name)
                except:
                    img = Photo()
                    img.name = nome_foto
                    img.image = name
                    img.caption = episodio.titolo
                    img.upload_date = datetime.datetime.now()
                    img.publish_date = datetime.datetime.now()

                    img.save()

                    episodio.foto.add(img)
                    episodio.save()
            except:
                print sys.exc_info()[0]
                print nome_foto
                print "problemi con download foto"

    except:
        ok = False
Beispiel #3
0
def download_foto(film,link_foto,tipo='classic'):
    #print 'download foto'
    count=0
    ok=True
    new_file_dir = os.path.dirname(settings.MEDIA_ROOT+film.data_ins.strftime("%Y"+os.sep+"%m"+os.sep))
    if not os.path.exists(new_file_dir):
        os.makedirs(new_file_dir)
    while ok==True:
        try:
            link=link_foto[count]
            pos=link.rfind('/')
            nome_foto=link[pos+1:]
            try:
                
                nome_foto=nome_foto.replace('%20','_')
                name = film.data_ins.strftime("%Y"+os.sep+"%m"+os.sep) + str(film.id) + nome_foto
                try:
                    image = urllib.URLopener()
                    image.retrieve(link,settings.MEDIA_ROOT + name)
                except:
                    image=None
                    logger_download.warning('foto non trovata')
                    logger_download.warning(sys.exc_info())
                    logger_download.info(link)
                #print link
                if image!=None:
                    try:
                        img = Photo.objects.get(image=name)
                    except:    
                        img = Photo()
                        img.name = nome_foto
                        img.image=name
                        img.upload_date = datetime.datetime.now()
                        img.publish_date = datetime.datetime.now()
                        img.save()
                        
                    #film.foto.add(img)
                    #film.save()
                    if img!=None:
                        try:
                            moviefoto=MovieFoto.objects.get(foto=img,movie=film)
                        except:
                            #nonlotrovo lo aggiungo
                            moviefoto=MovieFoto()
                            moviefoto.foto=img
                            moviefoto.movie=film
                            if tipo=='classic':
                                moviefoto.ordine=100
                            elif tipo=='locandina':
                                moviefoto.ordine=10
                            moviefoto.tipo=tipo
                            moviefoto.save()
                
            except:
                logger_download.warning('Problemi con il download di una foto')
                logger_download.warning(sys.exc_info())
                
                #print 'problemi con download foto'
                pass
            count=count+1
        except:
            ok=False