avwx.parsing.sanitization.pirep

PIREP sanitization support.

1"""PIREP sanitization support."""
2
3from avwx.parsing.sanitization.base import sanitize_string_with
4from avwx.parsing.sanitization.cleaners.replace import CURRENT
5
6clean_pirep_string = sanitize_string_with(CURRENT)
def clean_pirep_string(text: str, sans: avwx.structs.Sanitization) -> str:
25    def sanitize_report_string(text: str, sans: Sanitization) -> str:
26        """Provide sanitization for operations that work better when the report is a string."""
27        text = text.strip().upper().rstrip("=")
28        if len(text) < 4:
29            return text
30        # Standardize whitespace
31        text = " ".join(text.split())
32        # Prevent changes to station ID
33        stid, text = text[:4], text[4:]
34        # Replace invalid key-value pairs
35        for key, rep in replacements.items():
36            if key in text:
37                text = text.replace(key, rep)
38                sans.log(key, rep)
39        separated = separate_cloud_layers(text)
40        if text != separated:
41            sans.extra_spaces_needed = True
42        return stid + separated

Provide sanitization for operations that work better when the report is a string.