Ejemplo n.º 1
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
                )
Ejemplo n.º 2
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)
Ejemplo n.º 3
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
Ejemplo n.º 4
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