示例#1
0
def parse(report: str) -> PirepData:
    """
    Returns a PirepData object based on the given report
    """
    if not report:
        return None
    clean = _core.sanitize_report_string(report)
    wxdata, *_ = _core.sanitize_report_list(clean.split())
    sanitized = " ".join(wxdata)
    wxresp = {
        "raw": report,
        "sanitized": sanitized,
        "station": None,
        "remarks": None
    }
    wxdata = sanitized.split("/")
    wxresp.update(_root(wxdata.pop(0).strip()))
    for item in wxdata:
        if not item or len(item) < 2:
            continue
        tag = item[:2]
        item = item[2:].strip()
        if tag in _handlers:
            key, handler = _handlers[tag]
            wxresp[key] = handler(item)
        elif tag in _dict_handlers:
            wxresp.update(_dict_handlers[tag](item))
    return PirepData(**wxresp)
示例#2
0
def parse(report: str, issued: date = None) -> PirepData:
    """
    Returns a PirepData object based on the given report
    """
    if not report:
        return None
    sanitized = sanitization.sanitize_report_string(report)
    # NOTE: will need to implement PIREP-specific list clean
    resp = {
        "raw": report,
        "sanitized": sanitized,
        "station": None,
        "remarks": None
    }
    data = sanitized.split("/")
    resp.update(_root(data.pop(0).strip()))
    for item in data:
        if not item or len(item) < 2:
            continue
        tag = item[:2]
        item = item[2:].strip()
        if tag == "TM":
            resp["time"] = _time(item, issued)
        elif tag in _HANDLERS:
            key, handler = _HANDLERS[tag]
            resp[key] = handler(item)
        elif tag in _DICT_HANDLERS:
            resp.update(_DICT_HANDLERS[tag](item))
    return PirepData(**resp)
示例#3
0
def parse(report: str) -> PirepData:
    """
    Returns a PirepData object based on the given report
    """
    if not report:
        return None
    sanitized = core.sanitize_report_string(report)
    # NOTE: will need to implement PIREP-specific list clean
    resp = {
        "raw": report,
        "sanitized": sanitized,
        "station": None,
        "remarks": None
    }
    data = sanitized.split("/")
    resp.update(_root(data.pop(0).strip()))
    for item in data:
        if not item or len(item) < 2:
            continue
        tag = item[:2]
        item = item[2:].strip()
        if tag in _handlers:
            key, handler = _handlers[tag]
            resp[key] = handler(item)
        elif tag in _dict_handlers:
            resp.update(_dict_handlers[tag](item))
    return PirepData(**resp)