load_movies.py 844 B

12345678910111213141516171819202122232425262728
  1. # scripts/load_movies.py
  2. import os
  3. from app import app
  4. from database.database import db
  5. from models.models import DownloadedFile
  6. def add_movies_from_file(file_path):
  7. with open(file_path, 'r', encoding='utf-8') as file:
  8. movies = file.readlines()
  9. with app.app_context():
  10. for movie in movies:
  11. movie = movie.strip()
  12. if not DownloadedFile.query.filter_by(name=movie).first():
  13. new_movie = DownloadedFile(name=movie, downloaded=False)
  14. db.session.add(new_movie)
  15. db.session.commit()
  16. if __name__ == '__main__':
  17. # Assume the path to the movie file
  18. base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  19. database_path = os.path.join(base_dir, 'data', 'download.txt')
  20. file_path = database_path
  21. add_movies_from_file(file_path)