diff --git a/doorcontrol/tasks/scrapehidevents.py b/doorcontrol/tasks/scrapehidevents.py index 69b325e..7c42f30 100644 --- a/doorcontrol/tasks/scrapehidevents.py +++ b/doorcontrol/tasks/scrapehidevents.py @@ -18,13 +18,23 @@ def getMessages(door: Door): else: last_ts = datetime(2010, 1, 1) + retrieved_message_count = 0 + created_message_count = 0 for events_page in door.controller.get_events(last_ts): print(f"Importing {len(events_page)} events for {door.name}") - HIDEvent.objects.bulk_create( + created_messages = HIDEvent.objects.bulk_create( (HIDEvent.from_xml_attributes(door, event.attrib) for event in events_page), ignore_conflicts=True, ) + retrieved_message_count += len(events_page) + created_message_count += len(created_messages) + + return { + "retrieved": retrieved_message_count, + "created": created_message_count, + } + def q_getMessagesAllDoors(): # TODO: this should probably use async_iter