diff --git a/DataImporter.py b/DataImporter.py index e30faf452efc6f3873a591553cb80dd50ca971bc..56061fe6370d90464af82beda5579d74c7ff7605 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 a15573d17ad6eddd3413448f3a8080a2d5b163ad..78c1f25513874a7a220b3e6b4b8ad1cc391911ae 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)