def create_movie(db: SQLAlchemy, data: MovieData): movie = Movie.query.filter_by(imdb_id=data.imdb_id).first() if movie is None: data.look_up() movie = Movie(imdb_id=data.imdb_id, imdb_url=data.imdb_url, title=data.title, avatar=data.avatar, description=data.description, banner=data.banner, trailer=data.trailer, year=data.year, age=data.age, budget=data.budget, rating=data.rating, runtime=data.runtime, original_lang=data.original_lang, production_co=data.production_co) else: movie.imdb_url = data.imdb_url movie.title = data.title movie.avatar = data.avatar for genre in create_genre(db, data.genres): movie.genres.append(genre) for director in create_people(db, data.directors): movie.directors.append(director) for writer in create_people(db, data.writers): movie.writers.append(writer) for artist in create_people(db, data.artists): movie.artists.append(artist) for country in create_country(db, data.countries): movie.countries.append(country) for photo in create_photo(db, data.photos): movie.photos.append(photo) print(movie.to_dict()) db.session.add(movie) db.session.commit()
Movie.year == year, Movie.director == director).first() if not movie: movie = Movie() movie.api_id = movie_data[column_pos.get('api_id')] sys.stdout.write('\rNEW Movie %s' % movie.api_id) movie.title = movie_data[column_pos.get('title')] movie.year = movie_data[column_pos.get('year')] movie.director = movie_data[column_pos.get('director')] # Set actors actors = [ movie_data[column_pos.get('actor_1')], movie_data[column_pos.get('actor_2')], movie_data[column_pos.get('actor_3')] ] for actor_name in [a for a in actors if a]: actor = Actor.query.filter(Actor.name == actor_name).first() if not actor: actor = Actor(actor_name) movie.actors.append(actor) # Set IMDB url movie.imdb_url = get_imdb_url(movie.title, movie.year, movie.director) db.session.add(movie) else: sys.stdout.write('\rOLD Movie %s' % movie.api_id) location = Location(movie.id, movie_data[column_pos.get('locations')]) movie.locations.append(location) db.session.commit() sys.stdout.write('\r\n')
movie = Movie.query.filter(Movie.title == title, Movie.year == year, Movie.director == director).first() if not movie: movie = Movie() movie.api_id = movie_data[column_pos.get('api_id')] sys.stdout.write('\rNEW Movie %s' % movie.api_id) movie.title = movie_data[column_pos.get('title')] movie.year = movie_data[column_pos.get('year')] movie.director = movie_data[column_pos.get('director')] # Set actors actors = [ movie_data[column_pos.get('actor_1')], movie_data[column_pos.get('actor_2')], movie_data[column_pos.get('actor_3')] ] for actor_name in [a for a in actors if a]: actor = Actor.query.filter(Actor.name == actor_name).first() if not actor: actor = Actor(actor_name) movie.actors.append(actor) # Set IMDB url movie.imdb_url = get_imdb_url(movie.title, movie.year, movie.director) db.session.add(movie) else: sys.stdout.write('\rOLD Movie %s' % movie.api_id) location = Location(movie.id, movie_data[column_pos.get('locations')]) movie.locations.append(location) db.session.commit() sys.stdout.write('\r\n')