Hotfix for ZIP code lookup issue

This commit is contained in:
Ben 2025-07-02 19:01:05 -07:00
parent d3d57d7e0a
commit c949228aae
Signed by: webmaster
GPG key ID: A5FCBAF34E6E8B50
2 changed files with 19 additions and 8 deletions

View file

@ -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

View file

@ -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