def get_wind( data: List[str], units: Units ) -> Tuple[List[str], Number, Number, Number, List[Number]]: """Returns the report list and removed: Direction string, speed string, gust string, variable direction list """ direction, speed, gust = "", "", "" variable = [] if data: item = copy(data[0]) for rep in ["(E)"]: item = item.replace(rep, "") for replacements in (("O", "0"), ("/", ""), ("LKT", "KT"), ("GG", "G")): item = item.replace(*replacements) # 09010KT, 09010G15KT if (item.endswith("KT") or item.endswith("KTS") or item.endswith("MPS") or item.endswith("KMH") or ((len(item) == 5 or (len(item) >= 8 and item.find("G") != -1) and item.find("/") == -1) and (item[:5].isdigit() or (item.startswith("VRB") and item[3:5].isdigit())))): # In order of frequency if item.endswith("KT"): item = item.replace("KT", "") elif item.endswith("KTS"): item = item.replace("KTS", "") elif item.endswith("MPS"): units.wind_speed = "m/s" item = item.replace("MPS", "") elif item.endswith("KMH"): units.wind_speed = "km/h" item = item.replace("KMH", "") direction = item[:3] if "G" in item: g_index = item.find("G") gust = item[g_index + 1:] speed = item[3:g_index] else: speed = item[3:] direction = item[:3] data.pop(0) # Separated Gust if data and 1 < len( data[0]) < 4 and data[0][0] == "G" and data[0][1:].isdigit(): gust = data.pop(0)[1:] # Variable Wind Direction if (data and len(data[0]) == 7 and data[0][:3].isdigit() and data[0][3] == "V" and data[0][4:].isdigit()): variable = [ make_number(i, speak=i, literal=True) for i in data.pop(0).split("V") ] # Convert to Number direction = make_number(direction, speak=direction, literal=True) speed = make_number(speed.strip("BV")) gust = make_number(gust) return data, direction, speed, gust, variable
def get_wind(wxdata: [str], units: Units) -> ([str], Number, Number, Number, [Number]): """ Returns the report list and removed: Direction string, speed string, gust string, variable direction list """ direction, speed, gust = '', '', '' variable = [] if wxdata: item = copy(wxdata[0]) for rep in ['(E)']: item = item.replace(rep, '') for replacements in ( ('O', '0'), ('/', ''), ): item = item.replace(*replacements) #09010KT, 09010G15KT if item.endswith('KT') \ or item.endswith('KTS') \ or item.endswith('MPS') \ or item.endswith('KMH') \ or ((len(item) == 5 or (len(item) >= 8 and item.find('G') != -1) and item.find('/') == -1) and (item[:5].isdigit() or (item.startswith('VRB') and item[3:5].isdigit()))): #In order of frequency if item.endswith('KT'): item = item.replace('KT', '') elif item.endswith('KTS'): item = item.replace('KTS', '') elif item.endswith('MPS'): units.wind_speed = 'm/s' item = item.replace('MPS', '') elif item.endswith('KMH'): units.wind_speed = 'km/h' item = item.replace('KMH', '') direction = item[:3] if 'G' in item: g_index = item.find('G') gust = item[g_index + 1:] speed = item[3:g_index] else: speed = item[3:] wxdata.pop(0) #Separated Gust if wxdata and 1 < len( wxdata[0]) < 4 and wxdata[0][0] == 'G' and wxdata[0][1:].isdigit(): gust = wxdata.pop(0)[1:] #Variable Wind Direction if wxdata and len(wxdata[0]) == 7 and wxdata[0][:3].isdigit() \ and wxdata[0][3] == 'V' and wxdata[0][4:].isdigit(): variable = [make_number(i, speak=i) for i in wxdata.pop(0).split('V')] # Convert to Number direction = make_number(direction, speak=direction) speed = make_number(speed) gust = make_number(gust) return wxdata, direction, speed, gust, variable
def get_wind(wxdata: [str], units: Units) -> ([str], Number, Number, Number, [Number]): """ Returns the report list and removed: Direction string, speed string, gust string, variable direction list """ direction, speed, gust = '', '', '' variable = [] if wxdata: item = copy(wxdata[0]) for rep in ['(E)']: item = item.replace(rep, '') for replacements in ( ('O', '0'), ('/', ''), ): item = item.replace(*replacements) #09010KT, 09010G15KT if item.endswith('KT') \ or item.endswith('KTS') \ or item.endswith('MPS') \ or item.endswith('KMH') \ or ((len(item) == 5 or (len(item) >= 8 and item.find('G') != -1) and item.find('/') == -1) and (item[:5].isdigit() or (item.startswith('VRB') and item[3:5].isdigit()))): #In order of frequency if item.endswith('KT'): item = item.replace('KT', '') elif item.endswith('KTS'): item = item.replace('KTS', '') elif item.endswith('MPS'): units.wind_speed = 'm/s' item = item.replace('MPS', '') elif item.endswith('KMH'): units.wind_speed = 'km/h' item = item.replace('KMH', '') direction = item[:3] if 'G' in item: g_index = item.find('G') gust = item[g_index + 1:] speed = item[3:g_index] else: speed = item[3:] wxdata.pop(0) #Separated Gust if wxdata and 1 < len(wxdata[0]) < 4 and wxdata[0][0] == 'G' and wxdata[0][1:].isdigit(): gust = wxdata.pop(0)[1:] #Variable Wind Direction if wxdata and len(wxdata[0]) == 7 and wxdata[0][:3].isdigit() \ and wxdata[0][3] == 'V' and wxdata[0][4:].isdigit(): variable = [make_number(i, speak=i) for i in wxdata.pop(0).split('V')] # Convert to Number direction = make_number(direction, speak=direction) speed = make_number(speed) gust = make_number(gust) return wxdata, direction, speed, gust, variable