latest.src.energy_manager.apis.weather.get_hourly_weather

Functions

get_hourly_weather(→ Optional[pandas.DataFrame])

Fetches the hourly weather data for a given city and timestamp using the OpenWeatherMap

Module Contents

latest.src.energy_manager.apis.weather.get_hourly_weather.get_hourly_weather(city_name: str, timestamp: int, openweathermap_api_key: str) pandas.DataFrame | None

Fetches the hourly weather data for a given city and timestamp using the OpenWeatherMap API and formats it into a pandas DataFrame with specific columns.

This function retrieves historical weather data for a specific city and timestamp by making an API call to the OpenWeatherMap One Call Timemachine endpoint. The data is then processed into a DataFrame, which includes columns for datetime, temperature, and weather description. If the data cannot be retrieved or parsed, the function returns None.

Parameters:
  • city_name (str) – Name of the target city for which weather data is requested.

  • timestamp (int) – Unix timestamp representing the date and hour for fetching weather data.

  • openweathermap_api_key (str) – API key for accessing the OpenWeatherMap service.

Returns:

A DataFrame containing weather data with columns for datetime, temperature, and weather description, or None if data cannot be retrieved or parsed.

Return type:

Optional[pd.DataFrame]