doorcontrol: Add management command to scrape HID events

This commit is contained in:
Adam Goldsmith 2024-05-13 00:30:47 -04:00
parent 02aee01d20
commit 007253cdfd

View File

@ -0,0 +1,20 @@
from django.core.management.base import BaseCommand, CommandError
from doorcontrol.models import Door
from doorcontrol.tasks.scrapehidevents import getMessages
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument("door_names", nargs="*")
def handle(self, *args, door_names: list[str], verbosity: int, **options):
doors = Door.objects.all()
if door_names:
doors = doors.filter(name__in=door_names)
if len(doors) != len(door_names):
raise CommandError("Not all door names matched doors in database")
for door in doors:
print(door)
getMessages(door)