def import_ratings(user_name, ratings_path): user = User(name=user_name) session.add(user) with open(ratings_path) as f: reader = DictReader(f) for row in reader: film = Film() film.imdb_id = row['const'] rating = Rating(value=row['You rated']) rating.film = film rating.user = user film.title = row['Title'].decode('utf-8') session.add(film) session.add(rating) session.commit()
def _update_film(db, film_listbox, producer_listbox, film_id: int, user_film_title, user_film_year, user_film_producer_id, choose_window): film_title = user_film_title.get() film_year = user_film_year.get() film_producer_id = user_film_producer_id.get() if film_id and film_title and film_year and film_producer_id: errors_in_data = check_film_data(film_id, film_year, film_producer_id) if errors_in_data: messagebox.showerror("Error", errors_in_data) return db.update_film(db.current_db, Film(film_id, film_title, film_year, film_producer_id)) show_all_films(db, film_listbox) show_all_producers(db, producer_listbox) else: messagebox.showerror("Error", "Fields cannot be empty") choose_window.destroy()
def fill_db_with_top_250() -> None: """ Filling database with TOP 250 films uses get_top_250_films() generator from request.py nothing is returned """ logging.warning( f" ({datetime.now()}) Database is empty. Getting TOP 250 films.") for film in get_top_250_films(): film['frame'] = get_film_frame(film['filmId']) film['review'] = get_film_review(film['filmId'], film['nameRu'], film['nameEn']) new_film = Film(film) db.session.add(new_film) db.session.commit() logging.info(f" ({datetime.now()}) Film ID:{film['filmId']} added.") logging.info(f" ({datetime.now()}) Database filled with TOP 250 films.")
def films_update(slug=None): ''' Return list of films missing metadata. If a slug is provided, return requested film for update. ''' films = [] query = Film.select().where(Film.slug == slug if slug else Film.tmdb_id.is_null(True)) for film in query: films.append({ 'film': film.to_dict(extra=['year']), 'metadata': film.search_metadata(), 'barcodes': film.search_barcodes() }) return jsonify({'films': films})
def _add_film(db, user_film_id, user_film_title, user_film_year, user_film_producer_id, choose_window, producer_listbox, film_listbox): if db.current_db: film_id = user_film_id.get() film_title = user_film_title.get() film_year = user_film_year.get() film_p_id = user_film_producer_id.get() film_producer_id = user_film_producer_id.get() if film_id and film_title and film_year and film_producer_id: errors_in_data = check_film_data(film_id, film_year, film_p_id) if errors_in_data: messagebox.showerror("Error", errors_in_data) return db.insert_film(db.current_db, Film(film_id, film_title, film_year, film_p_id)) show_all_films(db, film_listbox) show_all_producers(db, producer_listbox) else: messagebox.showerror("Error", "Fields cannot be empty") else: messagebox.showerror("Error", "Open database before inserting") choose_window.destroy()
def film(slug): # Return film return jsonify( {'film': Film.get(slug=slug).as_dict(copies=True, barcodes=True)})
def films(): # Return films return jsonify({'films': [f.as_dict() for f in Film.select()]})
def film_update_barcodes(slug, barcode_slug): # Update film barcodes film = Film.get(slug=slug) film.update_barcodes(barcode_slug, save=True) return jsonify({'film': film.as_dict()})
def film_update_metadata(slug, tmdb_id): # Update film metadata film = Film.get(slug=slug) film.update_metadata(tmdb_id, save=True) return jsonify({'film': film.as_dict()})