summary refs log tree commit diff stats
diff options
context:
space:
mode:
authormounderfod <mounderfod@gmail.com>2023-07-19 16:33:49 +0200
committermounderfod <mounderfod@gmail.com>2023-07-19 16:33:49 +0200
commita85989cc62004489e790c64d8af25c4e02fbc20c (patch)
tree6fd6d8a2c4d618bcb6e3944b236ca5d2107fd263
parentc648b93501f41b1385d486d29407e777c2326a59 (diff)
downloadgopherhole-a85989cc62004489e790c64d8af25c4e02fbc20c.tar.gz
Revert "Make compatible with old Python"
This reverts commit c648b93501f41b1385d486d29407e777c2326a59.
-rw-r--r--app.py11
-rw-r--r--weather.py69
2 files changed, 41 insertions, 39 deletions
diff --git a/app.py b/app.py
index b1dc89e..873c99b 100644
--- a/app.py
+++ b/app.py
@@ -33,11 +33,12 @@ def handle(request):
         menu = []
         text = figlet.renderText(request.path[1:]).split("\n")
         menu += [Item(text=i) for i in text]
-        if request.path == "/news":
-            menu.append(Item(text="=== Provided by The Guardian ==="))
-            menu += news.get_news()
-        elif request.path == "/weather":
-            menu += weather.get_cities(request.query)
+        match request.path:
+            case "/news":
+                menu.append(Item(text="=== Provided by The Guardian ==="))
+                menu += news.get_news()
+            case "/weather":
+                menu += weather.get_cities(request.query)
         return menu
     else:
         return [Item(itype="3", text="Page not found")]
diff --git a/weather.py b/weather.py
index a8daac0..50b947a 100644
--- a/weather.py
+++ b/weather.py
@@ -10,34 +10,35 @@ load_dotenv()
 
 
 def get_code(code):
-    if code in [0]:
-        return "Clear sky"
-    if code in [1, 2, 3]:
-        return "Partly cloudy"
-    if code in [45, 48]:
-        return "Foggy"
-    if code in [51, 53, 55]:
-        return "Drizzle"
-    if code in [56, 57]:
-        return "Freezing drizzle"
-    if code in [61, 63, 65]:
-        return "Rain"
-    if code in [66, 67]:
-        return "Freezing rain"
-    if code in [71, 73, 675]:
-        return "Snow"
-    if code in [77]:
-        return "Snow grains"
-    if code in [80, 81, 82]:
-        return "Rain showers"
-    if code in [85, 86]:
-        return "Snow showers"
-    if code in [95]:
-        return "Thunderstorm"
-    if code in [96, 99]:
-        return "Thunderstorm with hail"
-
-    return "Unknown"
+    match code:
+        case 0:
+            return "Clear sky"
+        case 1 | 2 | 3:
+            return "Partly cloudy"
+        case 45 | 48:
+            return "Foggy"
+        case 51 | 53 | 55:
+            return "Drizzle"
+        case 56 | 57:
+            return "Freezing drizzle"
+        case 61 | 63 | 65:
+            return "Rain"
+        case 66 | 67:
+            return "Freezing rain"
+        case 71 | 73 | 675:
+            return "Snow"
+        case 77:
+            return "Snow grains"
+        case 80 | 81 | 82:
+            return "Rain showers"
+        case 85 | 86:
+            return "Snow showers"
+        case 95:
+            return "Thunderstorm"
+        case 96 | 99:
+            return "Thunderstorm with hail"
+        case _:
+            return "Unknown"
 
 
 def get_cities(query):
@@ -62,10 +63,10 @@ def get_weather(city):
     place = query.split("&city=")[1]
 
     print(f"https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}&hourly"
-          f"=temperature_2m,relativehumidity_2m,precipitation_probability,"
-          f"weathercode,windspeed_10m&daily=weathercode,"
-          f"temperature_2m_max,temperature_2m_min,sunrise,"
-          f"sunset&current_weather=true&timezone=auto")
+                        f"=temperature_2m,relativehumidity_2m,precipitation_probability,"
+                        f"weathercode,windspeed_10m&daily=weathercode,"
+                        f"temperature_2m_max,temperature_2m_min,sunrise,"
+                        f"sunset&current_weather=true&timezone=auto")
 
     data = requests.get(f"https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}&hourly"
                         f"=temperature_2m,relativehumidity_2m,precipitation_probability,"
@@ -77,9 +78,9 @@ def get_weather(city):
     result += f.renderText("weather").split("\n")
     f.setFont(font="small")
 
-    result.append("=" * 80)
+    result.append("="*80)
     result.append(f"{place}".center(80))
-    result.append("=" * 80)
+    result.append("="*80)
 
     result += f.renderText("hourly").split("\n")
     table_hourly = PrettyTable()
313' href='#n313'>313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374