delete_zombie_scrobbles.py 863 B

1234567891011121314151617181920212223242526272829
  1. from django.core.management.base import BaseCommand, no_translations
  2. from vrobbler.apps.scrobbles.utils import delete_zombie_scrobbles
  3. class Command(BaseCommand):
  4. def add_arguments(self, parser):
  5. parser.add_argument(
  6. "--delete",
  7. action="store_true",
  8. help="Delete poll instead of closing it",
  9. )
  10. def handle(self, *args, **options):
  11. dry_run = True
  12. if options["delete"]:
  13. dry_run = False
  14. scrobbles_found = delete_zombie_scrobbles(dry_run)
  15. if not scrobbles_found:
  16. print(f"No zombie scrobbles found to delete")
  17. return
  18. if not dry_run:
  19. print(f"Deleted {scrobbles_found} zombie scrobbles")
  20. return
  21. print(
  22. f"Found {scrobbles_found} zombie scrobbles, use --delete to remove them"
  23. )