Hotfix for ZIP code lookup issue
This commit is contained in:
parent
d3d57d7e0a
commit
c949228aae
2 changed files with 19 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
||||||
maubot: 0.1.0
|
maubot: 0.1.0
|
||||||
id: org.fiftyfiftyonearizona.reports.producerstopicenet
|
id: org.fiftyfiftyonearizona.reports.producerstopicenet
|
||||||
version: 1.2.0
|
version: 1.2.1
|
||||||
license: MIT
|
license: MIT
|
||||||
modules:
|
modules:
|
||||||
- producerstopicenet
|
- producerstopicenet
|
||||||
|
|
|
@ -48,6 +48,9 @@ class Config(BaseProxyConfig):
|
||||||
helper.copy("sendto")
|
helper.copy("sendto")
|
||||||
|
|
||||||
class ProducerStopIceNet(Plugin):
|
class ProducerStopIceNet(Plugin):
|
||||||
|
http: aiohttp.ClientSession
|
||||||
|
poll_task: asyncio.Future
|
||||||
|
|
||||||
# Runs on start to ceate polling "thread"
|
# Runs on start to ceate polling "thread"
|
||||||
async def start(self) -> None:
|
async def start(self) -> None:
|
||||||
await super().start()
|
await super().start()
|
||||||
|
@ -66,10 +69,16 @@ class ProducerStopIceNet(Plugin):
|
||||||
return upgrade_table
|
return upgrade_table
|
||||||
|
|
||||||
async def poll_loop(self):
|
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:
|
while True:
|
||||||
|
try:
|
||||||
await self.poll()
|
await self.poll()
|
||||||
# Sleep for n seconds
|
# Sleep for n seconds
|
||||||
await asyncio.sleep(self.config["refresh_delay"])
|
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):
|
def get_send_rooms(self, region_name):
|
||||||
room_ids = set()
|
room_ids = set()
|
||||||
|
@ -108,7 +117,10 @@ class ProducerStopIceNet(Plugin):
|
||||||
# Get page
|
# Get page
|
||||||
alert_url = "https://stopice.net/login/?alert=" + alert_id
|
alert_url = "https://stopice.net/login/?alert=" + alert_id
|
||||||
alert_id = alert_url.split('=')[-1]
|
alert_id = alert_url.split('=')[-1]
|
||||||
|
try:
|
||||||
alert_page = await self.http.get(alert_url)
|
alert_page = await self.http.get(alert_url)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
alert_soup = BeautifulSoup(await alert_page.text(), 'html.parser')
|
alert_soup = BeautifulSoup(await alert_page.text(), 'html.parser')
|
||||||
|
|
||||||
# Get the address and body text strings
|
# Get the address and body text strings
|
||||||
|
@ -126,14 +138,13 @@ class ProducerStopIceNet(Plugin):
|
||||||
zip_code = regex.findall(pattern_zip_code, alert_address)
|
zip_code = regex.findall(pattern_zip_code, alert_address)
|
||||||
if len(zip_code) >= 1: zip_code = zip_code[-1]
|
if len(zip_code) >= 1: zip_code = zip_code[-1]
|
||||||
else: zip_code = None
|
else: zip_code = None
|
||||||
self.log.debug(zip_code)
|
|
||||||
|
|
||||||
# Get state code from zip if not extracted otherwise
|
# Get state code from zip if not extracted otherwise
|
||||||
if region_code is None:
|
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:
|
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
|
continue
|
||||||
|
|
||||||
# Get state name from state code
|
# Get state name from state code
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue