weatherhack-api / utils /conversions.py
Ig0tU
first commit
a9814b6
raw
history blame contribute delete
767 Bytes
def convert_temperature(temp_c: float, unit: str) -> int:
if unit == "f":
return int((temp_c * 9 / 5) + 32)
elif unit == "s":
return int(temp_c + 273.15)
return int(temp_c)
def convert_wind_speed(speed_kmh: float, unit: str) -> int:
if unit == "f":
return int(speed_kmh * 0.621371) # km/h to mph
elif unit == "s":
return int(speed_kmh / 3.6) # km/h to m/s
return int(speed_kmh)
def convert_visibility(vis_km: float, unit: str) -> int:
if unit == "f":
return int(vis_km * 0.621371) # km to miles
return int(vis_km)
def convert_precip(precip_mm: float, unit: str) -> float:
if unit == "f":
return round(precip_mm * 0.0393701, 2) # mm to inches
return round(precip_mm, 2)