diff --git a/rootfs/etc/scripts/reformat.py b/rootfs/etc/scripts/reformat.py index d9c59ff..1a9adbc 100644 --- a/rootfs/etc/scripts/reformat.py +++ b/rootfs/etc/scripts/reformat.py @@ -12,6 +12,8 @@ from threading import Thread, current_thread from time import sleep +from util import geslookup + #from colorama import Fore def rx_thread(port, rxq): @@ -81,7 +83,7 @@ def thread_wrapper(func, *args): fn1 = compile(r"\/FN(?P\w+)\/") fn2 = compile(r"\/FMH(?P\w+),") -gs1 = compile(r"^\/(?P\w{7})\.") +gs1 = compile(r"[\s\/](?P\w{7})\.") while True: try: @@ -94,6 +96,7 @@ def thread_wrapper(func, *args): out = data + # convert station ID tag to frequency, remove tag try: station = data["source"]["station_id"] out["source"]["station_id"] = station[:station.rindex("-")] @@ -101,6 +104,28 @@ def thread_wrapper(func, *args): except: pass + # try to extract flight number + flight = "" + fl1 = fn1.search(data.get("message", "")) + if fl1: + flight = fl1.groupdict().get("fn") + if not flight: + fl2 = fn2.search(data.get("message", "")) + if fl2: + flight = fl2.groupdict().get("fn") + + if flight and len(flight) <= 9: + out["flight"] = flight + + # try to decode ground station + gsa = data.get("libacars", {}).get("arinc622", {}).get("gs_addr", "") + if not gsa: + ges1 = gs1.search(data.get("message", "")) + if ges1: + gsa = ges1.groupdict().get("gs") + if decoded := geslookup(gsa): + out["fromaddr_decoded"] = f"{gsa}/{geslookup(gsa)}" + if (getenv("LOG_IN_JSON")) or (getenv("LOG_IN_JSON_FILT") and "ACARS" == data.get("msg_name")): pprint(data) print() diff --git a/rootfs/etc/scripts/util.py b/rootfs/etc/scripts/util.py new file mode 100644 index 0000000..54cc044 --- /dev/null +++ b/rootfs/etc/scripts/util.py @@ -0,0 +1,127 @@ +gesLoc = { + "ABJCAYA": "Abidjan (Ivory Coast)", + "ACCFAYA": "Accra (Ghana)", + "AKLCDYA": "Auckland Oceanic (NZ)", + "ALGCAYA": "Alger (Algeria)", + "ANCATYA": "Anchorage Oceanic (USA)", + "ANCXFXA": "Anchorage Domestic (USA)", + "AUHABYA": "", + "AUHCAYA": "", + "BAHCEYA": "", + "BDOCAYA": "Bodo Oceanic (Norway)", + "BJSATYA": "", + "BJSGWYA": "Beijing (China)", + "BKKCAYA": "Thailand", + "BKKGWXA": "Bangkok (Thailand)", + "BNECAYA": "Brisbane (AUS)", + "BOMCAYA": "Mumbai (India)", + "BOMCDYA": "", + "BZVCAYA": "Brazzaville (Congo)", + "CAICAYA": "Egypt", + "CAICDYA": "Cairo (Egypt)", + "CANGWYA": "Guangzhou (China)", + "CAYCAYA": "Cayenne (French Guiana)", + "CCUCAYA": "Kolkata (India)", + "CCUCBYA": "Kolkata (India)", + "CDGATYA": "Paris (France)", + "CMBCAYA": "Colombo (Sri Lanka)", + "CMBCBYA": "Colombo (Sri Lanka)", + "CTUGWYA": "Chengdu (China)", + "DATSAXS": "", + "DDLCVXA": "Bodo (Norway)", + "DELCAYA": "Delhi (India)", + "DKRCAYA": "Dakar Oceanic (Senegal)", + "DOHATYA": "Doha (Qatar)", + "DXBEGEK": "", + "FIHCAYA": "Congo", + "FUKJJYA": "Fukuoka (Japan)", + "GDXE1XA": "Magadan (Russia)", + "GDXGWXA": "Magadan (Russia)", + "GVACBYA": "", + "GVSCAYA": "Sal Oceanic (Cape Verde)", + "GYDCDYA": "", + "HDQOILX": "", + "HKGCCYA": "Hong Kong", + "HRBGWYA": "Harbin (China)", + "JAKGWXA": "Jakarta (Indonesia)", + "JEDAAYA": "", + "JEDATYA": "", + "JNBCAYA": "Johannesburg Oceanic (SA)", + "KANCAYA": "Kano (Nigeria)", + "KMGGWYA": "Kunming (China)", + "KRTCAYA": "Khartoum (Sudan)", + "KRTCDYA": "Sudan", + "KULCAYA": "Kuala Lumpur (Malaysia)", + "LADCAYA": "Angola (Luanda)", + "LHWGWYA": "Lanzhou (China)", + "LISACYA": "Lisboa (Portugal)", + "LPAFAYA": "Canarias (Spain)", + "LXAGWYA": "Lhasa (China)", + "MAACAYA": "Chennai (India)", + "MADAAYA": "", + "MADCDYA": "", + "MCTASWY": "Muscat (Oman)", + "MELCAYA": "Melbourne (AUS)", + "MEXCAYA": "Mexico", + "MGQCAYA": "Ethiopia", + "MLECAYA": "Male (Maldives)", + "MNLCBYA": "Manila (Philippines)", + "MRUCAYA": "Mauritius (Mauritius)", + "MSTEC7X": "Maastricht (NL)", + "NANCDYA": "Nadi (Fiji)", + "NBOCAYA": "Kenya (Niarobi)", + "NDJCAYA": "N'Djamena (Chad)", + "NIMCAYA": "Niamey (Niger)", + "NKCCAYA": "Dakar Domestic (Senegal)", + "NYCODYA": "New York Oceanic (USA)", + "OAKODYA": "Oakland Oceanic (USA)", + "PAREUYA": "France", + "PIKCAYA": "Scottish (UK)", + "PIKCLXS": "Prestwick Domestic (UK)", + "PIKCLYA": "Prestwick Oceanic (UK)", + "PIKCPYA": "Shanwick (UK)", + "POMCAYA": "Port Moresby (PG)", + "POSCLYA": "Piarco (Trinidad)", + "PPTCDYA": "Tahiti (French Polynesia)", + "RECOEYA": "Atlantico (Brazil)", + "REKCAYA": "Reykjavik (Iceland)", + "RGNCAYA": "Yangon (Myanmar)", + "RIOCDYA": "", + "RPHIAYA": "Manila (Philippines)", + "RUHAAYA": "", + "SCLCAYA": "Antofagasta (Chile)", + "SELCAXH": "Seoul (Korea)", + "SEZCAYA": "Seychelles", + "SGNGWXA": "Ho Chi Minh (Vietnam)", + "SHAGWYA": "Shanghai (China)", + "SINCDYA": "Singapore", + "SINCXYA": "Singapore", + "SMACAYA": "Santa Maria (Portugal)", + "SNNCPXA": "Shannon (Ireland)", + "SOUCAYA": "London (UK)", + "SPLATYA": "Amsterdam Schipol (NL)", + "TASCAXH": "Tashkent (Uzbekistan)", + "TGUACAY": "Honduras (Cenamer)", + "TGUACYA": "Cenamar (Honduras)", + "TNRCAYA": "Antananarivo (Madagascar)", + "ULNGWXA": "Ulan Bataar (Mongolia)", + "UPGCAYA": "Makassar (Indonesia)", + "URCE1YA": "Urumqi (China)", + "URCGWYA": "Urum-Qi (China)", + "USADCXA": "USA Domestic (USA)", + "YEGCDYA": "Edmonton (Canada)", + "YEGE2YA": "Edmonton (Canada)", + "YQME2YA": "Moncton (Canada)", + "YQXD2YA": "Gander Domestic (Canada)", + "YQXE2YA": "Gander Oceanic (Canada)", + "YULE2YA": "Montreal (Canada)", + "YVRE2YA": "Vancouver (Canada)", + "YWGE2YA": "Winnipeg (Canada)", + "YYZE2YA": "Toronto (Canada)" +} + +def geslookup(gsa): + txt = gesLoc.get(gsa) + if not txt: + pass + return txt