diff --git a/main.py b/main.py index 4b18009..b27ab21 100755 --- a/main.py +++ b/main.py @@ -3,7 +3,6 @@ import os import json import locale -import pprint import argparse import requests from pathlib import Path @@ -32,7 +31,7 @@ def load_args(): def ask_api(latitude: float, longitude: float, altitude: int) -> dict: - """ """ + """ interrege l'API de https://yr.no """ url = f"{YR_NO_URL}compact.json?lat={latitude}&lon={longitude}&altitude={altitude}" headers = {"User-Agent": "DaikoMete/0.1 daiko@daiko.fr"} response = requests.get(url, headers=headers) @@ -44,32 +43,12 @@ def ask_api(latitude: float, longitude: float, altitude: int) -> dict: return json.loads(response.text) -def main(): - """Fonction principale""" - - args = load_args() - config_file = Path(args["config"]) - if not config_file.is_file(): - print(f"{config_file} n'est pas un fichier.") - os._exit(1) - - conf = Config(args["config"]) - try: - location = conf.get_location(args["location"]) - except AttributeError: - print(f"{args['location']} n'est pas configuré.") - os._exit(1) - - response = ask_api( - latitude = location['latitude'], - longitude = location['longitude'], - altitude = location['altitude'], - ) - +def display_full(api_response): + """ Affiche les informations météo complètes """ locale.setlocale(locale.LC_TIME, "fr_FR.utf8") cur_date = datetime.fromisoformat("1970-01-01T00:00:00Z").date() - for time in response["properties"]["timeseries"]: + for time in api_response["properties"]["timeseries"]: new_date = datetime.fromisoformat(time["time"]) if new_date.date() > cur_date: @@ -82,5 +61,31 @@ def main(): print(f" {cur_hour} : {cur_temp}° / {cur_humidity}%") +def main(): + """Fonction principale""" + + args = load_args() + config_file = Path(args["config"]) + + if not config_file.is_file(): + print(f"{config_file} n'est pas un fichier.") + os._exit(1) + + conf = Config(args["config"]) + try: + location = conf.get_location(args["location"]) + except AttributeError: + print(f"{args['location']} n'est pas configuré.") + os._exit(1) + + api_response = ask_api( + latitude=location["latitude"], + longitude=location["longitude"], + altitude=location["altitude"], + ) + + display_full(api_response) + + if __name__ == "__main__": main()