import_gamelist_xml_file.py 957 B

12345678910111213141516171819202122232425262728293031
  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(
  19. self.style.SUCCESS(f"Successfully imported {len(games)} games")
  20. )
  21. else:
  22. self.stdout.write(
  23. self.style.ERROR(
  24. "No games imported, check for gamelist.xml file or re-run scraper"
  25. )
  26. )