avwx.parsing.sanitization.cleaners.remove
Cleaners for elements that should be removed.
1"""Cleaners for elements that should be removed.""" 2 3from avwx.parsing.sanitization.base import RemoveItem 4 5_SHARED = { 6 "$", 7 "KT", # Place after extra-space-exists cleaners 8 "M", 9 ".", 10 "1/SM", 11} 12 13_CURRENT = { 14 "AUTO", 15 "COR", 16 "NSC", 17 "NCD", 18 "RTD", 19 "SPECI", 20 "CORR", 21} 22 23_METAR = { 24 *_SHARED, 25 *_CURRENT, 26 "METAR", 27 "CLR", 28 "SKC", 29} 30 31_TAF = { 32 *_SHARED, 33 *_CURRENT, 34 "TAF", 35 "TTF", 36} 37 38 39def remove_items_in(filter_out: set[str]) -> type[RemoveItem]: 40 """Generate a RemoveItem cleaner to filter a given set of strings.""" 41 42 class RemoveInList(RemoveItem): 43 """Cleaner to remove items in a list""" 44 45 def can_handle(self, item: str) -> bool: 46 return item in filter_out 47 48 return RemoveInList 49 50 51RemoveFromMetar = remove_items_in(_METAR) 52RemoveFromTaf = remove_items_in(_TAF) 53 54 55class RemoveTafAmend(RemoveItem): 56 """Remove amend signifier from start of report ('CCA', 'CCB', etc).""" 57 58 def can_handle(self, item: str) -> bool: 59 return len(item) == 3 and item.startswith("CC") and item[2].isalpha()
def
remove_items_in( filter_out: set[str]) -> type[avwx.parsing.sanitization.cleaners.base.RemoveItem]:
40def remove_items_in(filter_out: set[str]) -> type[RemoveItem]: 41 """Generate a RemoveItem cleaner to filter a given set of strings.""" 42 43 class RemoveInList(RemoveItem): 44 """Cleaner to remove items in a list""" 45 46 def can_handle(self, item: str) -> bool: 47 return item in filter_out 48 49 return RemoveInList
Generate a RemoveItem cleaner to filter a given set of strings.
RemoveFromMetar =
<class 'remove_items_in.<locals>.RemoveInList'>
RemoveFromTaf =
<class 'remove_items_in.<locals>.RemoveInList'>
56class RemoveTafAmend(RemoveItem): 57 """Remove amend signifier from start of report ('CCA', 'CCB', etc).""" 58 59 def can_handle(self, item: str) -> bool: 60 return len(item) == 3 and item.startswith("CC") and item[2].isalpha()
Remove amend signifier from start of report ('CCA', 'CCB', etc).
def
can_handle(self, item: str) -> bool:
59 def can_handle(self, item: str) -> bool: 60 return len(item) == 3 and item.startswith("CC") and item[2].isalpha()
Return True if the element can and needs to be cleaned.