summary refs log tree commit diff stats
diff options
context:
space:
mode:
authormounderfod <mounderfod@gmail.com>2023-07-19 16:12:43 +0200
committermounderfod <mounderfod@gmail.com>2023-07-19 16:12:43 +0200
commitc648b93501f41b1385d486d29407e777c2326a59 (patch)
tree56f99de7ba9fde651a9c84bf5273eea75f4248ad
parent3c02dbcca9caa17373c47e0fa1ce9cf4715a7c84 (diff)
downloadgopherhole-c648b93501f41b1385d486d29407e777c2326a59.tar.gz
Make compatible with old Python
-rw-r--r--app.py11
-rw-r--r--weather.py69
2 files changed, 39 insertions, 41 deletions
diff --git a/app.py b/app.py
index 873c99b..b1dc89e 100644
--- a/app.py
+++ b/app.py
@@ -33,12 +33,11 @@ def handle(request):
         menu = []
         text = figlet.renderText(request.path[1:]).split("\n")
         menu += [Item(text=i) for i in text]
-        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)
+        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)
         return menu
     else:
         return [Item(itype="3", text="Page not found")]
diff --git a/weather.py b/weather.py
index 50b947a..a8daac0 100644
--- a/weather.py
+++ b/weather.py
@@ -10,35 +10,34 @@ load_dotenv()
 
 
 def get_code(code):
-    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"
+    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"
 
 
 def get_cities(query):
@@ -63,10 +62,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,"
@@ -78,9 +77,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()