def parse_in(txt: str) -> (MetarData, Units): """ Parser for the International METAR variant """ units = Units(**IN_UNITS) clean = core.sanitize_report_string(txt) wxresp = {'raw': txt, 'sanitized': clean} wxdata, wxresp['remarks'] = core.get_remarks(clean) wxdata, wxresp['runway_visibility'], _ = core.sanitize_report_list(wxdata) wxdata, wxresp['station'], wxresp['time'] = core.get_station_and_time( wxdata) if 'CAVOK' not in 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'] = core.get_altimeter(wxdata, units, 'IN') if 'CAVOK' in wxdata: wxresp['visibility'] = core.make_number('CAVOK') wxresp['clouds'] = [] wxdata.remove('CAVOK') else: wxdata, wxresp['visibility'] = core.get_visibility(wxdata, units) wxresp['other'], wxresp['temperature'], wxresp[ 'dewpoint'] = core.get_temp_and_dew(wxdata) condition = core.get_flight_rules(wxresp['visibility'], core.get_ceiling(wxresp['clouds'])) 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_in(report: str) -> (MetarData, Units): """ Parser for the International METAR variant """ units = Units(**IN_UNITS) wxresp = {"raw": report} clean = _core.sanitize_report_string(report) wxdata, wxresp["remarks"] = _core.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"] = _core.get_runway_visibility(wxdata) if "CAVOK" not in 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"] = _core.get_altimeter(wxdata, units, "IN") if "CAVOK" in wxdata: wxresp["visibility"] = _core.make_number("CAVOK") wxresp["clouds"] = [] wxdata.remove("CAVOK") else: wxdata, wxresp["visibility"] = _core.get_visibility(wxdata, units) wxresp["other"], wxresp["temperature"], wxresp["dewpoint"] = _core.get_temp_and_dew( wxdata ) condition = _core.get_flight_rules( wxresp["visibility"], _core.get_ceiling(wxresp["clouds"]) ) 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_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_in(report: str, issued: date = None) -> (MetarData, Units): """ Parser for the International METAR variant """ units = Units(**IN_UNITS) resp = {"raw": report} resp["sanitized"], resp["remarks"], data = sanitize(report) data, resp["station"], resp["time"] = core.get_station_and_time(data) data, resp["runway_visibility"] = get_runway_visibility(data) if "CAVOK" not in data: data, resp["clouds"] = core.get_clouds(data) ( data, resp["wind_direction"], resp["wind_speed"], resp["wind_gust"], resp["wind_variable_direction"], ) = core.get_wind(data, units) data, resp["altimeter"] = get_altimeter(data, units, "IN") if "CAVOK" in data: resp["visibility"] = core.make_number("CAVOK") resp["clouds"] = [] data.remove("CAVOK") else: data, resp["visibility"] = core.get_visibility(data, units) data, resp["temperature"], resp["dewpoint"] = get_temp_and_dew(data) condition = core.get_flight_rules(resp["visibility"], core.get_ceiling(resp["clouds"])) resp["other"], resp["wx_codes"] = get_wx_codes(data) resp["flight_rules"] = FLIGHT_RULES[condition] resp["remarks_info"] = remarks.parse(resp["remarks"]) resp["time"] = core.make_timestamp(resp["time"], target_date=issued) return MetarData(**resp), units
def parse_na(report: str) -> (MetarData, Units): """ Parser for the North American METAR variant """ units = Units(**NA_UNITS) clean = core.sanitize_report_string(report) wxresp = {'raw': report, 'sanitized': clean} wxdata, wxresp['remarks'] = core.get_remarks(clean) wxdata = core.dedupe(wxdata) wxdata, wxresp['runway_visibility'], _ = core.sanitize_report_list(wxdata) wxdata, wxresp['station'], wxresp['time'] = core.get_station_and_time( 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'] = core.get_altimeter(wxdata, units, 'NA') wxdata, wxresp['visibility'] = core.get_visibility(wxdata, units) wxresp['other'], wxresp['temperature'], wxresp[ 'dewpoint'] = core.get_temp_and_dew(wxdata) condition = core.get_flight_rules(wxresp['visibility'], core.get_ceiling(wxresp['clouds'])) 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_na(report: str, issued: date = None) -> Tuple[MetarData, Units]: """Parser for the North American METAR variant""" units = Units(**NA_UNITS) resp = {"raw": report} resp["sanitized"], resp["remarks"], data = sanitize(report) data, resp["station"], resp["time"] = core.get_station_and_time(data) data, resp["runway_visibility"] = get_runway_visibility(data) data, resp["clouds"] = core.get_clouds(data) ( data, resp["wind_direction"], resp["wind_speed"], resp["wind_gust"], resp["wind_variable_direction"], ) = core.get_wind(data, units) data, resp["altimeter"] = get_altimeter(data, units, "NA") data, resp["visibility"] = core.get_visibility(data, units) data, resp["temperature"], resp["dewpoint"] = get_temp_and_dew(data) condition = core.get_flight_rules( resp["visibility"], core.get_ceiling(resp["clouds"]) ) resp["other"], resp["wx_codes"] = get_wx_codes(data) resp["flight_rules"] = FLIGHT_RULES[condition] resp["remarks_info"] = remarks.parse(resp["remarks"]) resp["time"] = core.make_timestamp(resp["time"], target_date=issued) return MetarData(**resp), units