def parse_in_line(line: str, units: Units) -> {str: str}: """ Parser for the International TAF forcast variant """ wxdata = core.dedupe(line.split()) wxdata = core.sanitize_report_list(wxdata) retwx = {"sanitized": " ".join(wxdata)} ( wxdata, retwx["type"], retwx["start_time"], retwx["end_time"], ) = get_type_and_times(wxdata) wxdata, retwx["wind_shear"] = get_wind_shear(wxdata) ( wxdata, retwx["wind_direction"], retwx["wind_speed"], retwx["wind_gust"], _, ) = core.get_wind(wxdata, units) if "CAVOK" in wxdata: retwx["visibility"] = core.make_number("CAVOK") retwx["clouds"] = [] wxdata.pop(wxdata.index("CAVOK")) else: wxdata, retwx["visibility"] = core.get_visibility(wxdata, units) wxdata, retwx["clouds"] = core.get_clouds(wxdata) ( retwx["other"], retwx["altimeter"], retwx["icing"], retwx["turbulence"], ) = get_alt_ice_turb(wxdata) return retwx
def test_sanitize_report_list(self): """ Tests a function which fixes common mistakes while the report is a list """ for line, fixed in ( ("KJFK AUTO 123456Z ////// KT 10SM 20/10", "KJFK 123456Z 10SM 20/10"), ("METAR EGLL CALM RETS 6SPM CLR Q 1000", "EGLL 00000KT TS P6SM Q1000"), ("TLPL 111200Z 111200Z11020KT Q1015", "TLPL 111200Z 11020KT Q1015"), ("SECU 151200Z 151200Z18002KT Q1027", "SECU 151200Z 18002KT Q1027"), ("OAKB 211230Z 360G17G32KT Q1011", "OAKB 211230Z 36017G32KT Q1011"), ("MHLC 090024Z 06012G22TK 5000", "MHLC 090024Z 06012G22KT 5000"), ("SKCL 211600Z 211600ZVRB04KT A3010", "SKCL 211600Z VRB04KT A3010"), ( "SVMG 072200Z //////KT 9999 FEW010 XX/XX Q1012", "SVMG 072200Z 9999 FEW010 Q1012", ), ("KJFK 1 1 1 1 1 1 2 1", "KJFK 1 2 1"), ): line, fixed = line.split(), fixed.split() self.assertEqual(core.sanitize_report_list(line), fixed)
def parse_na_line(line: str, units: Units) -> {str: str}: """ Parser for the North American TAF forcast variant """ wxdata = core.dedupe(line.split()) wxdata = core.sanitize_report_list(wxdata) retwx = {"sanitized": " ".join(wxdata)} ( wxdata, retwx["type"], retwx["start_time"], retwx["end_time"], ) = get_type_and_times(wxdata) wxdata, retwx["wind_shear"] = get_wind_shear(wxdata) ( wxdata, retwx["wind_direction"], retwx["wind_speed"], retwx["wind_gust"], _, ) = core.get_wind(wxdata, units) wxdata, retwx["visibility"] = core.get_visibility(wxdata, units) wxdata, retwx["clouds"] = core.get_clouds(wxdata) ( retwx["other"], retwx["altimeter"], retwx["icing"], retwx["turbulence"], ) = get_alt_ice_turb(wxdata) return retwx
def parse_na(report: str) -> (MetarData, Units): """ Parser for the North American METAR variant """ units = Units(**NA_UNITS) wxresp = {"raw": report} clean = core.sanitize_report_string(report) wxdata, wxresp["remarks"] = get_remarks(clean) wxdata = core.dedupe(wxdata) wxdata = core.sanitize_report_list(wxdata) wxresp["sanitized"] = " ".join(wxdata + [wxresp["remarks"]]) wxdata, wxresp["station"], wxresp["time"] = core.get_station_and_time( wxdata) wxdata, wxresp["runway_visibility"] = get_runway_visibility(wxdata) wxdata, wxresp["clouds"] = core.get_clouds(wxdata) ( wxdata, wxresp["wind_direction"], wxresp["wind_speed"], wxresp["wind_gust"], wxresp["wind_variable_direction"], ) = core.get_wind(wxdata, units) wxdata, wxresp["altimeter"] = get_altimeter(wxdata, units, "NA") wxdata, wxresp["visibility"] = core.get_visibility(wxdata, units) wxdata, wxresp["temperature"], wxresp["dewpoint"] = get_temp_and_dew( wxdata) condition = core.get_flight_rules(wxresp["visibility"], core.get_ceiling(wxresp["clouds"])) wxresp["other"], wxresp["wx_codes"] = get_wx_codes(wxdata) wxresp["flight_rules"] = FLIGHT_RULES[condition] wxresp["remarks_info"] = remarks.parse(wxresp["remarks"]) wxresp["time"] = core.make_timestamp(wxresp["time"]) return MetarData(**wxresp), units
def parse(report: str) -> AirepData: """ """ if not report: return None clean = core.sanitize_report_string(report) wxdata = core.sanitize_report_list(clean.split()) wxresp = {"raw": report, "sanitized": " ".join(wxdata)} print(wxdata) print(wxresp) return None