From 15d454f93aacef634269bb8d4a2578aa3e7d355f Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Fri, 29 Nov 2024 10:37:52 -0800 Subject: [PATCH] Update eas_alert_parser.py --- etc/eas_alert_parser.py | 50 +++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/etc/eas_alert_parser.py b/etc/eas_alert_parser.py index b89f986..40a32e4 100644 --- a/etc/eas_alert_parser.py +++ b/etc/eas_alert_parser.py @@ -12,29 +12,31 @@ pattern = re.compile(r'ZCZC.*?NWS-') while True: try: # Handle piped input - line=input().strip() + inp=input().strip() except EOFError: break - # only want EAS lines - if line.startswith("EAS:") or line.startswith("EAS (part):"): - content=line.split(maxsplit=1)[1] - if content=="NNNN": # end of EAS message - # write if we have something - if buff: - print("writing") - with open("alert.txt","w") as fh: - fh.write('\n'.join(buff)) - # prepare for new data - buff.clear() - seen.clear() - elif content in seen: - # don't need repeats' - continue - else: - # check for national weather service - match=pattern.search(content) - if match: - seen.add(content) - msg=EAS2Text(content).EASText - print("got message", msg) - buff.append(msg) \ No newline at end of file + # potentially take multiple lines in one buffered input + for line in inp.splitlines(): + # only want EAS lines + if line.startswith("EAS:") or line.startswith("EAS (part):"): + content=line.split(":", maxsplit=1)[1].strip() + if content=="NNNN": # end of EAS message + # write if we have something + if buff: + print("writing") + with open("alert.txt","w") as fh: + fh.write('\n'.join(buff)) + # prepare for new data + buff.clear() + seen.clear() + elif content in seen: + # don't need repeats + continue + else: + # check for national weather service + match=pattern.search(content) + if match: + seen.add(content) + msg=EAS2Text(content).EASText + print("got message", msg) + buff.append(msg) \ No newline at end of file