#!/usr/bin/env python3 import requests import locale import json import os from datetime import datetime from meteo.config import Config yr_no_url = "https://api.met.no/weatherapi/locationforecast/2.0/" def main(): """Fonction principale""" conf = Config("./meteo.yaml") location = conf.get_location("florac") url = f"{yr_no_url}compact.json?lat={location['latitude']}&lon={location['longitude']}&altitude={location['altitude']}" headers = {"User-Agent": "DaikoMete/0.1 daiko@daiko.fr"} response = requests.get(url, headers=headers) if response.status_code != 200: print("Error contacting API.") os._exit(1) j = json.loads(response.text) cur_date = datetime.fromisoformat("1970-01-01T00:00:00Z").date() locale.setlocale(locale.LC_TIME, "fr_FR.utf8") for time in j["properties"]["timeseries"]: new_date = datetime.fromisoformat(time["time"]) if new_date.date() > cur_date: print(new_date.strftime("%A, %d. %B %Y")) cur_date = new_date.date() cur_hour = new_date.strftime("%H:%M") cur_temp = time["data"]["instant"]["details"]["air_temperature"] cur_humidity = time["data"]["instant"]["details"]["relative_humidity"] print(f" {cur_hour} : {cur_temp}° / {cur_humidity}%") if __name__ == "__main__": main()