From c949228aaee7547af5f76bb656d6346bdd50b048 Mon Sep 17 00:00:00 2001 From: 50501AZ Webmaster Date: Wed, 2 Jul 2025 19:01:05 -0700 Subject: [PATCH] Hotfix for ZIP code lookup issue --- maubot.yaml | 2 +- producerstopicenet.py | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/maubot.yaml b/maubot.yaml index 6fe5d3e..d6ecaba 100644 --- a/maubot.yaml +++ b/maubot.yaml @@ -1,6 +1,6 @@ maubot: 0.1.0 id: org.fiftyfiftyonearizona.reports.producerstopicenet -version: 1.2.0 +version: 1.2.1 license: MIT modules: - producerstopicenet diff --git a/producerstopicenet.py b/producerstopicenet.py index 285b58b..9e56d12 100644 --- a/producerstopicenet.py +++ b/producerstopicenet.py @@ -48,6 +48,9 @@ class Config(BaseProxyConfig): helper.copy("sendto") class ProducerStopIceNet(Plugin): + http: aiohttp.ClientSession + poll_task: asyncio.Future + # Runs on start to ceate polling "thread" async def start(self) -> None: await super().start() @@ -66,10 +69,16 @@ class ProducerStopIceNet(Plugin): return upgrade_table async def poll_loop(self): + await asyncio.sleep(10) # Delay to avoid consumers from missing messages + self.log.debug("Started poll loop after startup delay") while True: - await self.poll() - # Sleep for n seconds - await asyncio.sleep(self.config["refresh_delay"]) + try: + await self.poll() + # Sleep for n seconds + await asyncio.sleep(self.config["refresh_delay"]) + except Exception as error: + self.log.fatal( f"An error occurred: {error}") + await asyncio.sleep(120) # For posterity def get_send_rooms(self, region_name): room_ids = set() @@ -108,7 +117,10 @@ class ProducerStopIceNet(Plugin): # Get page alert_url = "https://stopice.net/login/?alert=" + alert_id alert_id = alert_url.split('=')[-1] - alert_page = await self.http.get(alert_url) + try: + alert_page = await self.http.get(alert_url) + except: + continue alert_soup = BeautifulSoup(await alert_page.text(), 'html.parser') # Get the address and body text strings @@ -126,14 +138,13 @@ class ProducerStopIceNet(Plugin): zip_code = regex.findall(pattern_zip_code, alert_address) if len(zip_code) >= 1: zip_code = zip_code[-1] else: zip_code = None - self.log.debug(zip_code) # Get state code from zip if not extracted otherwise if region_code is None: - if zip_code is not None: region_code = zip_to_region_map[int(zip_code)/100] + if zip_code is not None: region_code = zip_to_region_code_map[int(zip_code)//100] if region_code is None: - self.log.debug(alert_id + "doesn't have a detectible region!") + self.log.debug(f"{alert_id}doesn't have a detectible region!") continue # Get state name from state code