Ajoute la vitesse du vent et sa direction
This commit is contained in:
50
main.py
50
main.py
@@ -12,7 +12,6 @@ from meteo.config import Config
|
|||||||
|
|
||||||
YR_NO_URL = "https://api.met.no/weatherapi/locationforecast/2.0/"
|
YR_NO_URL = "https://api.met.no/weatherapi/locationforecast/2.0/"
|
||||||
|
|
||||||
|
|
||||||
def load_args():
|
def load_args():
|
||||||
"""Charge l'action et les paramêtres communs a toutes les actions."""
|
"""Charge l'action et les paramêtres communs a toutes les actions."""
|
||||||
parser = argparse.ArgumentParser(description="Affiche la météo")
|
parser = argparse.ArgumentParser(description="Affiche la météo")
|
||||||
@@ -44,25 +43,58 @@ def ask_api(latitude: float, longitude: float, altitude: int) -> dict:
|
|||||||
return json.loads(response.text)
|
return json.loads(response.text)
|
||||||
|
|
||||||
|
|
||||||
def display_full(api_response):
|
def display_full(data):
|
||||||
""" Affiche les informations météo complètes """
|
""" Affiche les informations météo complètes """
|
||||||
locale.setlocale(locale.LC_TIME, "fr_FR.utf8")
|
locale.setlocale(locale.LC_TIME, "fr_FR.utf8")
|
||||||
cur_date = datetime.fromisoformat("1970-01-01T00:00:00Z").date()
|
cur_date = datetime.fromisoformat("1970-01-01T00:00:00Z").date()
|
||||||
|
|
||||||
for time in api_response["properties"]["timeseries"]:
|
for infos in data["properties"]["timeseries"]:
|
||||||
new_date = datetime.fromisoformat(time["time"])
|
new_date = datetime.fromisoformat(infos["time"])
|
||||||
|
|
||||||
if new_date.date() > cur_date:
|
if new_date.date() > cur_date:
|
||||||
print(new_date.strftime("%A, %d. %B %Y"))
|
print(new_date.strftime("%A, %d. %B %Y"))
|
||||||
cur_date = new_date.date()
|
cur_date = new_date.date()
|
||||||
|
|
||||||
cur_hour = new_date.strftime("%H:%M")
|
time = new_date.strftime("%H:%M")
|
||||||
cur_temp = time["data"]["instant"]["details"]["air_temperature"]
|
|
||||||
|
|
||||||
cur_temp_str = coloring_temperature(cur_temp)
|
temperature = coloring_temperature(
|
||||||
|
infos["data"]["instant"]["details"]["air_temperature"]
|
||||||
|
)
|
||||||
|
|
||||||
|
wind_speed = infos["data"]["instant"]["details"]["wind_speed"]
|
||||||
|
|
||||||
cur_humidity = time["data"]["instant"]["details"]["relative_humidity"]
|
wind_direction = diplay_wind_direction(
|
||||||
print(f" {cur_hour} : {cur_temp_str}° / {cur_humidity}%")
|
infos["data"]["instant"]["details"]["wind_from_direction"]
|
||||||
|
)
|
||||||
|
|
||||||
|
cur_humidity = infos["data"]["instant"]["details"]["relative_humidity"]
|
||||||
|
print(f" {time} : {temperature}° / {cur_humidity}% / {wind_direction} {wind_speed} m/s")
|
||||||
|
|
||||||
|
|
||||||
|
def diplay_wind_direction(degrees: float) -> str:
|
||||||
|
""" Retourne une fleche indicant la direction du vent"""
|
||||||
|
if 22.5 <= degrees < 67.5:
|
||||||
|
return '↗'
|
||||||
|
|
||||||
|
if 67.5 <= degrees < 112.5:
|
||||||
|
return '→'
|
||||||
|
|
||||||
|
if 112.5 <= degrees < 157.5:
|
||||||
|
return '↘'
|
||||||
|
|
||||||
|
if 157.5 <= degrees < 202.5:
|
||||||
|
return '↓'
|
||||||
|
|
||||||
|
if 202.5 <= degrees < 247.5:
|
||||||
|
return '↙'
|
||||||
|
|
||||||
|
if 247.5 <= degrees < 292.5:
|
||||||
|
return '←'
|
||||||
|
|
||||||
|
if 292.5 <= degrees < 337.5:
|
||||||
|
return '↖'
|
||||||
|
|
||||||
|
return '↑'
|
||||||
|
|
||||||
|
|
||||||
def coloring_temperature(temperature: float) -> str:
|
def coloring_temperature(temperature: float) -> str:
|
||||||
|
Reference in New Issue
Block a user