doorcontrol: Add management command to scrape HID events
This commit is contained in:
parent
02aee01d20
commit
007253cdfd
20
doorcontrol/management/commands/scrape_hid_events.py
Normal file
20
doorcontrol/management/commands/scrape_hid_events.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user