From 56643540f640124b00559ef6967531fb199bbfe2 Mon Sep 17 00:00:00 2001
From: Lennard Geese <lennard.geese@sva.de>
Date: Wed, 16 Apr 2025 16:38:36 +0200
Subject: [PATCH] Adjust fetchWeather for lists of multiple events

---
 DataImporter.py | 21 +++++++++++++++------
 main.py         |  2 +-
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/DataImporter.py b/DataImporter.py
index e30faf4..56061fe 100644
--- a/DataImporter.py
+++ b/DataImporter.py
@@ -7,6 +7,7 @@ from abc import ABC
 
 import requests
 from fastf1.core import Session
+from fastf1.ergast import fetch_day
 from fastf1.events import EventSchedule, Event
 
 from DataAnalyser import DataAnalyser
@@ -21,17 +22,25 @@ class DataImporter(DataHandler, ABC):
     sessions. If the method does not require one of these, it should not be part of this class.
     """
 
-
-
-    def fetchEventWeather(self, event: Event | SessionIdentifier):
+    def fetchWeather(self, event: Event | SessionIdentifier | list[Event] | list[SessionIdentifier]):
         """
-        Fetch session weather from the wikipedia entry for the specified event.
-        :param event: The event or identifier for any session of the event to fetch weather for.
-        :return: Weather conditions as string
+        Fetch session weather from the wikipedia entry for the specified event(s).
+        :param event: The event or identifier for any session of the event to fetch weather for. Alternatively a list of
+        these.
+        :return: Weather conditions as string, or a list of such strings if a list is provided.
         """
+
+        # Recursive call if list provided
+        if isinstance(event, list):
+            weatherEntries: list[string] = []
+            for e in event:
+                weatherEntries.append(self.fetchWeather(e))
+
+        # Convert from SessionIdentifier to Event if needed
         if isinstance(event, SessionIdentifier):
             event = self.importEvent(event.year, event.event)
 
+        # Fetch weather
         wikiHtml = self.__importWikiHtml(event)
         analyser = DataAnalyser()
         weather = analyser.extractWeatherFromHtml(wikiHtml)
diff --git a/main.py b/main.py
index a15573d..78c1f25 100644
--- a/main.py
+++ b/main.py
@@ -37,7 +37,7 @@ class Main:
     def testNewRainRaceFetching(self):
         dataHandler: Main.DataHandlingPackage = Main.DataHandlingPackage()
         sessionIdentifier: SessionIdentifier = SessionIdentifier(2024, "Brazil", "R")
-        weather = dataHandler.importer.fetchEventWeather(sessionIdentifier)
+        weather = dataHandler.importer.fetchWeather(sessionIdentifier)
         print(weather)
 
 
-- 
GitLab