# scripts/load_movies.py import os from app import app from database.database import db from models.models import DownloadedFile def add_movies_from_file(file_path): with open(file_path, 'r', encoding='utf-8') as file: movies = file.readlines() with app.app_context(): for movie in movies: movie = movie.strip() if not DownloadedFile.query.filter_by(name=movie).first(): new_movie = DownloadedFile(name=movie, downloaded=False) db.session.add(new_movie) db.session.commit() if __name__ == '__main__': # Assume the path to the movie file base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) database_path = os.path.join(base_dir, 'data', 'download.txt') file_path = database_path add_movies_from_file(file_path)