Putting ZIP code in front of message
This commit is contained in:
parent
94186bde4e
commit
25a7368798
2 changed files with 15 additions and 7 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.1.0
|
version: 1.1.1
|
||||||
license: MIT
|
license: MIT
|
||||||
modules:
|
modules:
|
||||||
- producerstopicenet
|
- producerstopicenet
|
||||||
|
|
|
@ -39651,18 +39651,26 @@ class ProducerStopIceNet(Plugin):
|
||||||
state_code = regex.findall(pattern_state_code, alert_address)
|
state_code = regex.findall(pattern_state_code, alert_address)
|
||||||
if len(state_code) >= 1: state_code = state_code[-1].upper()
|
if len(state_code) >= 1: state_code = state_code[-1].upper()
|
||||||
else: state_code = None
|
else: state_code = None
|
||||||
|
|
||||||
|
# Get ZIP code
|
||||||
|
pattern_zip_code = r'[0-9]{5}'
|
||||||
|
zip_code = regex.findall(pattern_zip_code, alert_address)
|
||||||
|
if len(zip_code) >= 1: zip_code = zip_code[-1]
|
||||||
|
else: zip_code = None
|
||||||
|
|
||||||
|
# Get state code from zip if not extracted otherwise
|
||||||
if state_code is None:
|
if state_code is None:
|
||||||
# Get ZIP code
|
|
||||||
pattern_zip_code = r'\b[0-9]{5}\b'
|
|
||||||
zip_code = regex.findall(pattern_zip_code, alert_address)
|
|
||||||
if len(zip_code) >= 1: zip_code = zip_code[-1]
|
|
||||||
else: zip_code = None
|
|
||||||
if zip_code is not None: state_code = zip_to_state_map[int(zip_code)]
|
if zip_code is not None: state_code = zip_to_state_map[int(zip_code)]
|
||||||
|
|
||||||
|
# Get state name from state code
|
||||||
|
if state_code is None: continue
|
||||||
state_name = state_code_to_name_map[state_code.upper()]
|
state_name = state_code_to_name_map[state_code.upper()]
|
||||||
|
|
||||||
# Only proceed if state name is specified
|
# Only proceed if state name is specified
|
||||||
if state_name is not None and state_name.lower() in self.config["send_configs"]:
|
if state_name is not None and state_name.lower() in self.config["send_configs"]:
|
||||||
message = "!" + self.config["command_prefix"] + " " + state_name + " " + alert_body
|
message = "!" + self.config["command_prefix"] + " " + state_name + " "
|
||||||
|
message += (zip_code if zip_code is not None else "") + " "
|
||||||
|
message += alert_body
|
||||||
|
|
||||||
for room_id in self.config["send_configs"][state_name.lower()]:
|
for room_id in self.config["send_configs"][state_name.lower()]:
|
||||||
await self.client.send_text(room_id, message)
|
await self.client.send_text(room_id, message)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue