avwx.parsing.sanitization.cleaners.cloud
Cleaners for cloud elements.
1"""Cleaners for cloud elements.""" 2 3from avwx.static.core import CLOUD_LIST 4 5 6def separate_cloud_layers(text: str) -> str: 7 """Check for missing spaces in front of cloud layers. 8 Ex: TSFEW004SCT012FEW///CBBKN080 9 """ 10 for cloud in CLOUD_LIST: 11 if cloud in text and f" {cloud}" not in text: 12 start, counter = 0, 0 13 while text.count(cloud) != text.count(f" {cloud}"): 14 cloud_index = start + text[start:].find(cloud) 15 if len(text[cloud_index:]) >= 3: 16 target = text[cloud_index + len(cloud) : cloud_index + len(cloud) + 3] 17 if target.isdigit() or not target.strip("/"): 18 text = f"{text[:cloud_index]} {text[cloud_index:]}" 19 start = cloud_index + len(cloud) + 1 20 # Prevent infinite loops 21 if counter > text.count(cloud): 22 break 23 counter += 1 24 return text
def
separate_cloud_layers(text: str) -> str:
7def separate_cloud_layers(text: str) -> str: 8 """Check for missing spaces in front of cloud layers. 9 Ex: TSFEW004SCT012FEW///CBBKN080 10 """ 11 for cloud in CLOUD_LIST: 12 if cloud in text and f" {cloud}" not in text: 13 start, counter = 0, 0 14 while text.count(cloud) != text.count(f" {cloud}"): 15 cloud_index = start + text[start:].find(cloud) 16 if len(text[cloud_index:]) >= 3: 17 target = text[cloud_index + len(cloud) : cloud_index + len(cloud) + 3] 18 if target.isdigit() or not target.strip("/"): 19 text = f"{text[:cloud_index]} {text[cloud_index:]}" 20 start = cloud_index + len(cloud) + 1 21 # Prevent infinite loops 22 if counter > text.count(cloud): 23 break 24 counter += 1 25 return text
Check for missing spaces in front of cloud layers. Ex: TSFEW004SCT012FEW///CBBKN080