import_gamelist_xml_file.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from django.core.management.base import BaseCommand, CommandError
  2. from games.utils import import_gamelist_file_to_db_for_system
  3. class Command(BaseCommand):
  4. help = "Import all games found in a given gamelist XML file"
  5. def add_arguments(self, parser):
  6. parser.add_argument("system", type=str)
  7. parser.add_argument(
  8. "--file",
  9. action="store_true",
  10. help="Import from specific file",
  11. )
  12. parser.add_argument(
  13. "--full-scan",
  14. type=bool,
  15. default=False,
  16. help="Update all files, even ones we already know about",
  17. )
  18. def handle(self, *args, **options):
  19. games = import_gamelist_file_to_db_for_system(
  20. options["system"],
  21. options["file"],
  22. options["full_scan"],
  23. )
  24. if games:
  25. self.stdout.write(
  26. self.style.SUCCESS(f"Successfully imported {len(games)} games")
  27. )
  28. else:
  29. self.stdout.write(
  30. self.style.ERROR(
  31. "No games imported, check for gamelist.xml file or re-run scraper"
  32. )
  33. )