Ajoute de la couleur sur les températures
This commit is contained in:
29
main.py
29
main.py
@@ -7,6 +7,7 @@ import argparse
|
||||
import requests
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
from sty import fg, bg, ef, rs
|
||||
from meteo.config import Config
|
||||
|
||||
YR_NO_URL = "https://api.met.no/weatherapi/locationforecast/2.0/"
|
||||
@@ -57,8 +58,34 @@ def display_full(api_response):
|
||||
|
||||
cur_hour = new_date.strftime("%H:%M")
|
||||
cur_temp = time["data"]["instant"]["details"]["air_temperature"]
|
||||
|
||||
cur_temp_str = coloring_temperature(cur_temp)
|
||||
|
||||
cur_humidity = time["data"]["instant"]["details"]["relative_humidity"]
|
||||
print(f" {cur_hour} : {cur_temp}° / {cur_humidity}%")
|
||||
print(f" {cur_hour} : {cur_temp_str}° / {cur_humidity}%")
|
||||
|
||||
|
||||
def coloring_temperature(temperature: float) -> str:
|
||||
""" A partir de la température retourne une chaine de caractères colorisée """
|
||||
if temperature >= 40.0:
|
||||
return fg.magenta + str(temperature) + fg.rs
|
||||
|
||||
if temperature >= 30.0:
|
||||
return fg.red + str(temperature) + fg.rs
|
||||
|
||||
if temperature >= 25.0:
|
||||
return fg(255, 150, 50) + str(temperature) + fg.rs
|
||||
|
||||
if temperature >= 20.0:
|
||||
return fg.yellow + str(temperature) + fg.rs
|
||||
|
||||
if temperature >= 10.0:
|
||||
return str(temperature)
|
||||
|
||||
if temperature >= 0.0:
|
||||
return fg.cyan + str(cur_temp) + fg.rs
|
||||
|
||||
return fg.blue + str(cur_temp) + fg.rs
|
||||
|
||||
|
||||
def main():
|
||||
|
@@ -9,6 +9,7 @@ dependencies = [
|
||||
"pycurl>=7.45.6",
|
||||
"pyyaml>=6.0.2",
|
||||
"requests>=2.32.4",
|
||||
"sty>=1.0.6",
|
||||
]
|
||||
|
||||
[dependency-groups]
|
||||
|
11
uv.lock
generated
11
uv.lock
generated
@@ -124,6 +124,7 @@ dependencies = [
|
||||
{ name = "pycurl" },
|
||||
{ name = "pyyaml" },
|
||||
{ name = "requests" },
|
||||
{ name = "sty" },
|
||||
]
|
||||
|
||||
[package.dev-dependencies]
|
||||
@@ -138,6 +139,7 @@ requires-dist = [
|
||||
{ name = "pycurl", specifier = ">=7.45.6" },
|
||||
{ name = "pyyaml", specifier = ">=6.0.2" },
|
||||
{ name = "requests", specifier = ">=2.32.4" },
|
||||
{ name = "sty", specifier = ">=1.0.6" },
|
||||
]
|
||||
|
||||
[package.metadata.requires-dev]
|
||||
@@ -246,6 +248,15 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/7c/e4/56027c4a6b4ae70ca9de302488c5ca95ad4a39e190093d6c1a8ace08341b/requests-2.32.4-py3-none-any.whl", hash = "sha256:27babd3cda2a6d50b30443204ee89830707d396671944c998b5975b031ac2b2c", size = 64847, upload-time = "2025-06-09T16:43:05.728Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sty"
|
||||
version = "1.0.6"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/76/6a/aad1817e60f07e5ebc111affee15d4dff9d324981005310566c40f08786c/sty-1.0.6.tar.gz", hash = "sha256:d43ecb71b7bad0b56d622cb219d0be303c16fcb4143b84d1465ded22e29baa00", size = 12217, upload-time = "2023-11-27T13:57:12.931Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/ec/89/22b3b7f25f67d04690e3b565ca89062a6e7afb1e7124342d5b5b22e8f014/sty-1.0.6-py3-none-any.whl", hash = "sha256:2b1eba187b3961644f797f97177f939c109c916d3d3a2cb6784454d1f1ce4983", size = 12553, upload-time = "2023-11-27T13:57:11.4Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "urllib3"
|
||||
version = "2.5.0"
|
||||
|
Reference in New Issue
Block a user