TextParser Cleanup

This commit is contained in:
Marat Fayzullin 2024-05-01 23:45:12 -04:00
parent 0acde34abf
commit 907eede566
1 changed files with 5 additions and 5 deletions

View File

@ -110,11 +110,11 @@ class TextParser(LineBasedModule):
out = self.parse(line) out = self.parse(line)
# If running as a service and writing to a log file... # If running as a service and writing to a log file...
if self.service and self.filePfx is not None: if self.service and self.filePfx is not None:
if out and len(out) > 0: if out:
# If parser returned output, write it into log file # If parser returned output, write it into log file
self.writeFile(str(out).encode("utf-8")) self.writeFile(str(out).encode("utf-8"))
self.writeFile(b"\n") self.writeFile(b"\n")
elif out is None and len(line) > 0: elif out is None and len(line)>0:
# Write input into log file, including end-of-line # Write input into log file, including end-of-line
self.writeFile(line) self.writeFile(line)
self.writeFile(b"\n") self.writeFile(b"\n")
@ -213,15 +213,15 @@ class PageParser(TextParser):
super().__init__(filePrefix="PAGE", service=service) super().__init__(filePrefix="PAGE", service=service)
def parse(self, msg: bytes): def parse(self, msg: bytes):
# No result yet
out = None
# Steer message to POCSAG or FLEX parser # Steer message to POCSAG or FLEX parser
if msg.startswith(b"POCSAG"): if msg.startswith(b"POCSAG"):
out = self.parsePocsag(msg.decode('utf-8', 'replace')) out = self.parsePocsag(msg.decode('utf-8', 'replace'))
elif msg.startswith(b"FLEX"): elif msg.startswith(b"FLEX"):
out = self.parseFlex(msg.decode('utf-8', 'replace')) out = self.parseFlex(msg.decode('utf-8', 'replace'))
else:
out = None
# Ignore filtered messages # Ignore filtered messages
if out is None: if not out:
return {} return {}
# Add frequency, if known # Add frequency, if known
if self.frequency: if self.frequency: