diff --git a/webhooks/handlers.py b/webhooks/handlers.py index 3dee5e1..4166a21 100644 --- a/webhooks/handlers.py +++ b/webhooks/handlers.py @@ -41,10 +41,16 @@ def _refresh_bcf(self, save: bool) -> None: ) except Exception: viewpoints = [] - if len(viewpoints) > 0: - self.notification.payload["topic"]["snapshot_url"] = viewpoints[0][ - "snapshot" - ]["snapshot_data"] + snapshot_data = next( + ( + viewpoint["snapshot"]["snapshot_data"] + for viewpoint in viewpoints + if viewpoint["snapshot"] + ), + None, + ) + if snapshot_data: + self.notification.payload["topic"]["snapshot_url"] = snapshot_data if save: self.notification.save()