import_gamelist_xml_file.py 921 B

1234567891011121314151617181920212223242526272829
  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. def handle(self, *args, **options):
  13. games = import_gamelist_file_to_db_for_system(
  14. options["system"],
  15. options["file"],
  16. )
  17. if games:
  18. self.stdout.write(self.style.SUCCESS(f"Successfully imported {len(games)}"))
  19. else:
  20. self.stdout.write(
  21. self.style.ERROR(
  22. "No games imported, check for gamelist.xml file or re-run scraper"
  23. )
  24. )