def load_gravatar(self, id):
        userlikees = UserLikees.objects.get(pk=id)

        hash = hashlib.md5(userlikees.email).hexdigest()
        url = 'http://www.gravatar.com/avatar/' + hash + '.png'

        if userlikees.image is None:
            gravatar = Image(url=url)
            gravatar.save()
            userlikees.image_id = gravatar.id
            userlikees.save()
        else:
            userlikees.image.url = url
            userlikees.image.save()
    def load_gravatar(self, id):
        userlikees = UserLikees.objects.get(pk=id)

        hash = hashlib.md5(userlikees.email).hexdigest()
        url = 'http://www.gravatar.com/avatar/' + hash + '.png'

        if userlikees.image is None:
            gravatar = Image(url = url)
            gravatar.save()
            userlikees.image_id = gravatar.id
            userlikees.save()
        else:
            userlikees.image.url = url
            userlikees.image.save()
    def load_facebook_avatar(self, id):
        userlikees = UserLikees.objects.get(pk=id)

        prefs = self.get_user_settings(id)
        facebook_id = prefs['facebook_id']

        url = 'https://graph.facebook.com/' + facebook_id + '/picture'

        if userlikees.image is None:
            gravatar = Image(url=url)
            gravatar.save()
            userlikees.image_id = gravatar.id
            userlikees.save()
        else:
            userlikees.image.url = url
            userlikees.image.save()
    def load_facebook_avatar(self, id):
        userlikees = UserLikees.objects.get(pk=id)
        
        prefs = self.get_user_settings(id)
        facebook_id = prefs['facebook_id']

        url = 'https://graph.facebook.com/' + facebook_id + '/picture'

        if userlikees.image is None:
            gravatar = Image(url = url)
            gravatar.save()
            userlikees.image_id = gravatar.id
            userlikees.save()
        else:
            userlikees.image.url = url
            userlikees.image.save()
Example #5
0
def createMovie(entrada):
    print('Result: ' + entrada['titulo'])
    
    # Realizamos la carga de Item-Pelicula

    lang = entrada['language']
    name_code_m = getMultiCode()
    name_default_m = entrada['original_name']
    alternative_code_m = getMultiCode()
    alternative_name_m = entrada['alternative_name']
    overview_code_m = getMultiCode()
    overview_name_m = entrada['overview']
    tagline_code_m = getMultiCode()
    tagline_default_m = entrada['tagline']
    
    multiOriginalName = Multilanguage(code=name_code_m, language=lang, literal=name_default_m)
    multiOriginalName.save()
    
    multiAlternativeName = Multilanguage(code=alternative_code_m, language=lang, literal=alternative_name_m)
    multiAlternativeName.save()
    
    multiOverview = Multilanguage(code=overview_code_m, language=lang, literal=overview_name_m)
    multiOverview.save()
    
    tagline = Multilanguage(code=tagline_code_m, language=lang, literal=tagline_default_m)
    tagline.save()
    
    imageThumb = Image(url=entrada['image":{"type":"poster","size":"cover'],date=datetime.date.today())
    imageThumb.save()
    
    imageBig = Image(url=entrada['image":{"type":"poster","size":"mid'],date=datetime.date.today())
    imageThumb.save()
    
    categories = [] 
    
    for category in entrada['genres']:
        categs = Category.objects.filter(name_default_m=category['name'])
        for cat in categs:
            cat_code_m = getMultiCode()
            cat_name_m = category['name']
            categoryMult = Multilanguage(code=cat_code_m, language=lang, literal=cat_name_m)
            categoryMult.save()
            cat = Category(name_code_m=cat_code_m, name_default_m=cat_name_m)
            cat.save()
        
        categories.append(cat)
        

    
    #Company.objects.get()
    
    item = Movie(released=entrada['released'], 
                homepage=entrada['homepage'],
                votes_count=entrada['votes'],
                version=entrada['version'],
                name_code_m=name_code_m,
                name_default_m=name_default_m,
                alternative_code_m=alternative_code_m,
                overview_code_m=overview_code_m,
                overview_name_m=overview_name_m,
                tagline_code_m=tagline_code_m,
                tagline_default_m=tagline_default_m,
                type=entrada['type'],
                image=imageBig,
                thumb=imageThumb,
                runtime=entrada['runtime'],
                trailer=entrada['trailer'],
                id_imdb=entrada['imdb_id'],
                id_tmdb=entrada['id'],
                categories = categories
                )
Example #6
0
def createMovie(entradas):
    # Realizamos la carga de Item-Pelicula
    for entrada in entradas:
        
        if entrada['adult']:
            raise AdultException('adult = true')
            break

        # Movie type, ignoramos series de peliculas
        if entrada['movie_type'] == 'movie series':
            break
 
        # Comprobamos si ya existe la pelicula en la bbdd
        movie = Movie.objects.filter(id_tmdb=entrada['id'])
        
        if not movie:            
            original_name = entrada['original_name']
               
            alternative_name = None
            if entrada['alternative_name'] is not None:
                alternative_name = entrada['alternative_name']
            
            overview_name = None
            if entrada['overview'] is not None:
                overview_name = entrada['overview']
            
            # image
            image_ = None
            thumb_ = None
            for image in entrada['posters']:
                for e in image.values():
                    if thumb_ is None and  e['type'] == 'poster' and e['size'] == 'cover':
                        thumb_ = Image(url=e['url'],date=datetime.date.today())
                        thumb_.save()
                       
                    if image_ is None and e['type'] == 'poster' and e['size'] == 'mid':
                        image_ = Image(url=e['url'],date=datetime.date.today())
                        image_.save()

            
            relDate = '1900-01-01'
            if entrada['released'] is not None and entrada['released'] != '':
                relDate = entrada['released'] 

            # item.
            item = Movie(released=relDate, 
                        homepage=entrada['homepage'],
                        version=entrada['version'],
                        type='Movie',
                        name_en=original_name,
                        original_name=original_name,
                        alternative_name=alternative_name,
                        overview_en=overview_name,
                        tagline_en=entrada['tagline'],
                        runtime=entrada['runtime'],
                        trailer=entrada['trailer'],
                        id_imdb=entrada['imdb_id'],
                        id_tmdb=entrada['id'],
                        image=image_,
                        thumb=thumb_
                        )
            
            item.save()
        
            # categories.
            for category in entrada['genres']:
                if category['name'] == 'Sporting Event':
                    raise SportingEventException('sporting_event = true')

                if category['name'] == 'Fan Film':
                    raise FanFilmException('fan_film = true')
                
                categsR = Category.objects.filter(name_en=category['name'])
                categs = None
                
                if not categsR:
                    categs = Category(name_en=category['name'])
                    categs.save()
            
                if categsR:
                    categs = categsR.get()
                
                if categs is not None:
                    item.categories.add(categs)

            #studios.
            for studio in entrada['studios']:
                studioTemp = Company.objects.filter(name=studio['name'])
                studioR = None

                if not studioTemp:
                    studioR = Company(name=studio['name'])
                    studioR.save()
                
                if studioTemp:
                    studioR = studioTemp.get()
                
                rol = Role(item=item, company=studioR)
                rol.save()
                   

 
            # produced.
            for produced in entrada['countries']:
                countryR = Country.objects.filter(id=produced['code'])
                
                if countryR is not None:
                    for country in countryR:      
                        item.produced.add(country)

            # cast.
            for cast in entrada['cast']:
                personTemp = Person.objects.filter(name=cast['name'])
#                try:
#                    personTemp.get()
#                except:
#                    print personTemp

                personR = None            

                if not personTemp:
                    image_person = None
                    if cast['profile'] is not None and cast['profile'] != '':
                        image_per_str = cast['profile']
                        image_per_str = image_per_str.replace('thumb.jpg', 'profile.jpg')
                        image_person = Image(url=image_per_str,date=datetime.date.today())
                        image_person.save()
                    
                    personR = Person(name=cast['name'],tmdb_id=cast['id'],image=image_person)
                    personR.save()
                    

                if personTemp:
                    personR = personTemp.get()

                #Tenemos en personR la persona dada de alta
                job = cast['job']
                jobTemp = Job.objects.filter(name_en=job)

                jobR = None

                if not jobTemp:
                    jobR = Job(name_en=job)
                    jobR.save()

                if jobTemp:
                    jobR = jobTemp.get()

                ijcp = Item_Job_Cast_Person(person=personR, item=item, job=jobR)
                ijcp.save()
 
            item.save()

            break
Example #7
0
def createMovie(entrada):
    print('Result: ' + entrada['titulo'])

    # Realizamos la carga de Item-Pelicula

    lang = entrada['language']
    name_code_m = getMultiCode()
    name_default_m = entrada['original_name']
    alternative_code_m = getMultiCode()
    alternative_name_m = entrada['alternative_name']
    overview_code_m = getMultiCode()
    overview_name_m = entrada['overview']
    tagline_code_m = getMultiCode()
    tagline_default_m = entrada['tagline']

    multiOriginalName = Multilanguage(code=name_code_m,
                                      language=lang,
                                      literal=name_default_m)
    multiOriginalName.save()

    multiAlternativeName = Multilanguage(code=alternative_code_m,
                                         language=lang,
                                         literal=alternative_name_m)
    multiAlternativeName.save()

    multiOverview = Multilanguage(code=overview_code_m,
                                  language=lang,
                                  literal=overview_name_m)
    multiOverview.save()

    tagline = Multilanguage(code=tagline_code_m,
                            language=lang,
                            literal=tagline_default_m)
    tagline.save()

    imageThumb = Image(url=entrada['image":{"type":"poster","size":"cover'],
                       date=datetime.date.today())
    imageThumb.save()

    imageBig = Image(url=entrada['image":{"type":"poster","size":"mid'],
                     date=datetime.date.today())
    imageThumb.save()

    categories = []

    for category in entrada['genres']:
        categs = Category.objects.filter(name_default_m=category['name'])
        for cat in categs:
            cat_code_m = getMultiCode()
            cat_name_m = category['name']
            categoryMult = Multilanguage(code=cat_code_m,
                                         language=lang,
                                         literal=cat_name_m)
            categoryMult.save()
            cat = Category(name_code_m=cat_code_m, name_default_m=cat_name_m)
            cat.save()

        categories.append(cat)

    #Company.objects.get()

    item = Movie(released=entrada['released'],
                 homepage=entrada['homepage'],
                 votes_count=entrada['votes'],
                 version=entrada['version'],
                 name_code_m=name_code_m,
                 name_default_m=name_default_m,
                 alternative_code_m=alternative_code_m,
                 overview_code_m=overview_code_m,
                 overview_name_m=overview_name_m,
                 tagline_code_m=tagline_code_m,
                 tagline_default_m=tagline_default_m,
                 type=entrada['type'],
                 image=imageBig,
                 thumb=imageThumb,
                 runtime=entrada['runtime'],
                 trailer=entrada['trailer'],
                 id_imdb=entrada['imdb_id'],
                 id_tmdb=entrada['id'],
                 categories=categories)
    def load_avatar(self, id, f):

        sub = ''

        if not f.content_type is None:
            main, sub = f.content_type.split('/')
            if not (main == 'image' and sub in ['jpeg', 'gif', 'png']):
                raise Exception(_('JPEG, PNG, GIF only.'))

        filename = str(id) + '.' + sub
        filepath_temp = settings.AVATAR_PATH + 'temp/' + filename
        filepath = settings.AVATAR_PATH + filename
        destination = open(filepath_temp, 'wb+')

        for chunk in f.chunks():
            destination.write(chunk)

        destination.close()
        import os
        import Image as ImagePIL

        img = None

        try:
            img = ImagePIL.open(filepath_temp)
            x, y = img.size
        except:
            os.remove(filepath_temp)
            raise Exception('Error al obtener la imagen.')

        # Checkeamos que el GIF no es animado
        if sub == 'gif':

            is_ani = True

            try:
                img.seek(1)
            except EOFError:
                is_ani = False

            if is_ani:
                raise Exception('No se aceptan animaciones GIF.')

        if y > 100 or x > 100:
            os.remove(filepath_temp)
            raise Exception('Imagen demasiado grande, tamanyo maximo 100x100.')

        import shutil
        shutil.copy(filepath_temp, filepath)
        os.remove(filepath_temp)

        url = '/avatar/' + filename

        userlikees = UserLikees.objects.get(pk=id)

        if userlikees.image is None:
            avatar = Image(url=url)
            avatar.save()
            userlikees.image_id = avatar.id
            userlikees.save()
        else:
            userlikees.image.url = url
            userlikees.image.save()
Example #9
0
def createMovie(entradas):
    # Realizamos la carga de Item-Pelicula
    for entrada in entradas:

        if entrada['adult']:
            raise AdultException('adult = true')
            break

        # Movie type, ignoramos series de peliculas
        if entrada['movie_type'] == 'movie series':
            break

        # Comprobamos si ya existe la pelicula en la bbdd
        movie = Movie.objects.filter(id_tmdb=entrada['id'])

        if not movie:
            original_name = entrada['original_name']

            alternative_name = None
            if entrada['alternative_name'] is not None:
                alternative_name = entrada['alternative_name']

            overview_name = None
            if entrada['overview'] is not None:
                overview_name = entrada['overview']

            # image
            image_ = None
            thumb_ = None
            for image in entrada['posters']:
                for e in image.values():
                    if thumb_ is None and e['type'] == 'poster' and e[
                            'size'] == 'cover':
                        thumb_ = Image(url=e['url'],
                                       date=datetime.date.today())
                        thumb_.save()

                    if image_ is None and e['type'] == 'poster' and e[
                            'size'] == 'mid':
                        image_ = Image(url=e['url'],
                                       date=datetime.date.today())
                        image_.save()

            relDate = '1900-01-01'
            if entrada['released'] is not None and entrada['released'] != '':
                relDate = entrada['released']

            # item.
            item = Movie(released=relDate,
                         homepage=entrada['homepage'],
                         version=entrada['version'],
                         type='Movie',
                         name_en=original_name,
                         original_name=original_name,
                         alternative_name=alternative_name,
                         overview_en=overview_name,
                         tagline_en=entrada['tagline'],
                         runtime=entrada['runtime'],
                         trailer=entrada['trailer'],
                         id_imdb=entrada['imdb_id'],
                         id_tmdb=entrada['id'],
                         image=image_,
                         thumb=thumb_)

            item.save()

            # categories.
            for category in entrada['genres']:
                if category['name'] == 'Sporting Event':
                    raise SportingEventException('sporting_event = true')

                if category['name'] == 'Fan Film':
                    raise FanFilmException('fan_film = true')

                categsR = Category.objects.filter(name_en=category['name'])
                categs = None

                if not categsR:
                    categs = Category(name_en=category['name'])
                    categs.save()

                if categsR:
                    categs = categsR.get()

                if categs is not None:
                    item.categories.add(categs)

            #studios.
            for studio in entrada['studios']:
                studioTemp = Company.objects.filter(name=studio['name'])
                studioR = None

                if not studioTemp:
                    studioR = Company(name=studio['name'])
                    studioR.save()

                if studioTemp:
                    studioR = studioTemp.get()

                rol = Role(item=item, company=studioR)
                rol.save()

            # produced.
            for produced in entrada['countries']:
                countryR = Country.objects.filter(id=produced['code'])

                if countryR is not None:
                    for country in countryR:
                        item.produced.add(country)

            # cast.
            for cast in entrada['cast']:
                personTemp = Person.objects.filter(name=cast['name'])
                #                try:
                #                    personTemp.get()
                #                except:
                #                    print personTemp

                personR = None

                if not personTemp:
                    image_person = None
                    if cast['profile'] is not None and cast['profile'] != '':
                        image_per_str = cast['profile']
                        image_per_str = image_per_str.replace(
                            'thumb.jpg', 'profile.jpg')
                        image_person = Image(url=image_per_str,
                                             date=datetime.date.today())
                        image_person.save()

                    personR = Person(name=cast['name'],
                                     tmdb_id=cast['id'],
                                     image=image_person)
                    personR.save()

                if personTemp:
                    personR = personTemp.get()

                #Tenemos en personR la persona dada de alta
                job = cast['job']
                jobTemp = Job.objects.filter(name_en=job)

                jobR = None

                if not jobTemp:
                    jobR = Job(name_en=job)
                    jobR.save()

                if jobTemp:
                    jobR = jobTemp.get()

                ijcp = Item_Job_Cast_Person(person=personR,
                                            item=item,
                                            job=jobR)
                ijcp.save()

            item.save()

            break
Example #10
0
    def load_avatar(self, id, f):

        sub = ''

        if not f.content_type is None:
            main, sub = f.content_type.split('/')
            if not (main == 'image' and sub in ['jpeg', 'gif', 'png']):
                raise Exception(_('JPEG, PNG, GIF only.'))
        
        filename = str(id) + '.' + sub 
        filepath_temp = settings.AVATAR_PATH  + 'temp/' + filename
        filepath = settings.AVATAR_PATH + filename
        destination = open(filepath_temp, 'wb+')
        
        for chunk in f.chunks():
            destination.write(chunk)
        
        destination.close()
        import os
        import Image as ImagePIL
        
        img = None
        
        try:
            img = ImagePIL.open(filepath_temp)
            x, y = img.size
        except:
            os.remove(filepath_temp)
            raise Exception('Error al obtener la imagen.')
     
        # Checkeamos que el GIF no es animado
        if sub == 'gif':

            is_ani = True 

            try:
                img.seek(1)
            except EOFError:
                is_ani = False

            if is_ani:
                raise Exception('No se aceptan animaciones GIF.')

        if y > 100 or x > 100:
            os.remove(filepath_temp)
            raise Exception('Imagen demasiado grande, tamanyo maximo 100x100.')
       
        import shutil
        shutil.copy(filepath_temp, filepath)
        os.remove(filepath_temp)

        url = '/avatar/' + filename

        userlikees = UserLikees.objects.get(pk=id)

        if userlikees.image is None:
            avatar = Image(url = url)
            avatar.save()
            userlikees.image_id = avatar.id
            userlikees.save()
        else:
            userlikees.image.url = url
            userlikees.image.save()