def parse(station: str, report: str) -> (TafData, Units): """ Returns TafData and Units dataclasses with parsed data and their associated units """ if not report: return None, None valid_station(station) while len(report) > 3 and report[:4] in ("TAF ", "AMD ", "COR "): report = report[4:] retwx = { "end_time": None, "raw": report, "remarks": None, "start_time": None } report = _core.sanitize_report_string(report) _, station, time = _core.get_station_and_time(report[:20].split()) retwx["station"] = station retwx["time"] = _core.make_timestamp(time) report = report.replace(station, "") if time: report = report.replace(time, "").strip() if uses_na_format(station): use_na = True units = Units(**NA_UNITS) else: use_na = False units = Units(**IN_UNITS) # Find and remove remarks report, retwx["remarks"] = _core.get_taf_remarks(report) # Split and parse each line lines = _core.split_taf(report) parsed_lines = parse_lines(lines, units, use_na) # Perform additional info extract and corrections if parsed_lines: parsed_lines[-1]["other"], retwx["max_temp"], retwx[ "min_temp"] = _core.get_temp_min_and_max(parsed_lines[-1]["other"]) if not (retwx["max_temp"] or retwx["min_temp"]): parsed_lines[0]["other"], retwx["max_temp"], retwx[ "min_temp"] = _core.get_temp_min_and_max( parsed_lines[0]["other"]) # Set start and end times based on the first line start, end = parsed_lines[0]["start_time"], parsed_lines[0]["end_time"] parsed_lines[0]["end_time"] = None retwx["start_time"], retwx["end_time"] = start, end parsed_lines = _core.find_missing_taf_times(parsed_lines, start, end) parsed_lines = _core.get_taf_flight_rules(parsed_lines) # Extract Oceania-specific data if retwx["station"][0] == "A": parsed_lines[-1]["other"], retwx["alts"], retwx[ "temps"] = _core.get_oceania_temp_and_alt( parsed_lines[-1]["other"]) # Convert to dataclass retwx["forecast"] = [TafLineData(**line) for line in parsed_lines] return TafData(**retwx), units
def test_get_taf_remarks(self): """ Tests that remarks are removed from a TAF report """ for txt, rmk in ( ("KJFK test", ""), ("KJFK test RMK test", "RMK test"), ("KJFK test FCST test", "FCST test"), ("KJFK test AUTOMATED test", "AUTOMATED test"), ): report, remarks = _core.get_taf_remarks(txt) self.assertEqual(report, "KJFK test") self.assertEqual(remarks, rmk)
def test_get_taf_remarks(self): """ Tests that remarks are removed from a TAF report """ for txt, rmk in ( ('KJFK test', ''), ('KJFK test RMK test', 'RMK test'), ('KJFK test FCST test', 'FCST test'), ('KJFK test AUTOMATED test', 'AUTOMATED test'), ): report, remarks = _core.get_taf_remarks(txt) self.assertEqual(report, 'KJFK test') self.assertEqual(remarks, rmk)