Update common.py

This comprehends the PHGR custom message that MUST be terminated by "/" and the standard PHG message of 4 chars.  The math "Should" be done for the "R" in terms of direction but that has been omitted.
This commit is contained in:
TheCranston 2021-09-28 20:18:11 -04:00 committed by Rossen Georgiev
parent a3e205f001
commit dc90983cb6
1 changed files with 16 additions and 10 deletions

View File

@ -151,17 +151,23 @@ def parse_data_extentions(body):
if nrq.isdigit():
parsed.update({'nrq': int(nrq)})
else:
match = re.findall(r"^(PHG(\d[\x30-\x7e]\d\d[0-9A-Z]?))", body)
match = re.findall(r"^(PHG(\d[\x30-\x7e]\d\d[0-9A-Z]?\/))", body)
if match:
ext, phg = match[0]
body = body[len(ext):]
parsed.update({'phg': phg})
else:
match = re.findall(r"^RNG(\d{4})", body)
if match:
rng = match[0]
body = body[7:]
parsed.update({'rng': int(rng) * 1.609344}) # miles to km
ext, phg = match[0]
body = body[len(ext):]
parsed.update({'phg': phg})
else:
match = re.findall(r"^(PHG(\d[\x30-\x7e]\d\d))", body)
if match:
ext, phg = match[0]
body = body[len(ext):]
parsed.update({'phg': phg})
else:
match = re.findall(r"^RNG(\d{4})", body)
if match:
rng = match[0]
body = body[7:]
parsed.update({'rng': int(rng) * 1.609344}) # miles to km
return body, parsed