Skip to content
Snippets Groups Projects
Commit 56643540 authored by Lennard Geese's avatar Lennard Geese
Browse files

Adjust fetchWeather for lists of multiple events

parent 51ee533f
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment