From 3459d00a8aafc511c8bc281f9d5a13b5a300d67d Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sun, 10 Sep 2023 03:16:47 +0200 Subject: [PATCH] try to parse flight numbers better --- owrx/aeronautical.py | 8 +++++++- owrx/hfdl/dumphfdl.py | 7 ++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/owrx/aeronautical.py b/owrx/aeronautical.py index 22bb6f93..44c0f240 100644 --- a/owrx/aeronautical.py +++ b/owrx/aeronautical.py @@ -1,6 +1,7 @@ from owrx.map import Map, LatLngLocation, Source from csdr.module import JsonParser from abc import ABCMeta +import re class AirplaneLocation(LatLngLocation): @@ -45,9 +46,11 @@ class AcarsSource(Source): class AcarsProcessor(JsonParser, metaclass=ABCMeta): + flightRegex = re.compile("^([0-9A-Z]{2})0*([0-9A-Z]+$)") + def processAcars(self, acars: dict, icao: str = None): if "flight" in acars: - flight_id = acars["flight"] + flight_id = self.processFlight(acars["flight"]) elif "reg" in acars: flight_id = acars['reg'].lstrip(".") else: @@ -73,3 +76,6 @@ class AcarsProcessor(JsonParser, metaclass=ABCMeta): Map.getSharedInstance().updateLocation( source, AirplaneLocation(msg), "ACARS over {}".format(self.mode) ) + + def processFlight(self, raw): + return self.flightRegex.sub(r"\g<1>\g<2>", raw) diff --git a/owrx/hfdl/dumphfdl.py b/owrx/hfdl/dumphfdl.py index fb38df2d..2eb1d96f 100644 --- a/owrx/hfdl/dumphfdl.py +++ b/owrx/hfdl/dumphfdl.py @@ -75,15 +75,16 @@ class HFDLMessageParser(AcarsProcessor): if "pos" in hfnpdu: pos = hfnpdu["pos"] if abs(pos['lat']) <= 90 and abs(pos['lon']) <= 180: + flight = self.processFlight(hfnpdu["flight_id"]) msg = { "lat": pos["lat"], "lon": pos["lon"], - "flight": hfnpdu["flight_id"] + "flight": flight } if icao is None: - source = HfdlSource(hfnpdu["flight_id"]) + source = HfdlSource(flight) else: - source = IcaoSource(icao, flight=hfnpdu["flight_id"]) + source = IcaoSource(icao, flight=flight) if "utc_time" in hfnpdu: ts = self.processTimestamp(**hfnpdu["utc_time"]) elif "time" in hfnpdu: