From 007253cdfda3d30ae4fccbfef1065d9f277b07b3 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Mon, 13 May 2024 00:30:47 -0400 Subject: [PATCH] doorcontrol: Add management command to scrape HID events --- .../management/commands/scrape_hid_events.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 doorcontrol/management/commands/scrape_hid_events.py diff --git a/doorcontrol/management/commands/scrape_hid_events.py b/doorcontrol/management/commands/scrape_hid_events.py new file mode 100644 index 0000000..cbd248c --- /dev/null +++ b/doorcontrol/management/commands/scrape_hid_events.py @@ -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)