Skip to content

Switch from Current One Call API 2.5 API to 5 Day / 3 Hour Forecast API#12

Open
SheriffKoder wants to merge 1 commit intomixj93:masterfrom
SheriffKoder:fix/api-change
Open

Switch from Current One Call API 2.5 API to 5 Day / 3 Hour Forecast API#12
SheriffKoder wants to merge 1 commit intomixj93:masterfrom
SheriffKoder:fix/api-change

Conversation

@SheriffKoder
Copy link
Copy Markdown

@SheriffKoder SheriffKoder commented Jan 3, 2026

What

This PR migrates the weather widget from using the One Call API 2.5 API to the 5 Day / 3 Hour Forecast API (which uses the same API key from openweathermap and is available for FREE also). The widget derives current weather, hourly forecasts, and daily forecasts from a single forecast API endpoint.

Why

The One Call API 2.5 API is possibly not available and causing an error to users.
The 5 Day / 3 Hour Forecast API is available on the FREE tier uses a single request and fixes the issue of no data available from the One Call API 2.5 API:

  • Provides forecasts every 3 hours for 5 days (40 data points total)

How

  1. API Endpoint Change: Updated the API path from /data/2.5/onecall to /data/2.5/forecast to use the forecast endpoint.

  2. Data Transformation: Added a transformForecastData() function that:

    • Extracts current weather from the first forecast item in the API response
    • Maps the first 6 forecast items (18 hours) to hourly forecasts
    • Aggregates 3-hour forecasts into daily summaries using the aggregateToDaily() helper function
  3. Daily Forecast Aggregation: Implemented aggregateToDaily() function that:

    • Groups 3-hour forecast intervals by date
    • Calculates daily min/max temperatures from all intervals in each day
    • Selects weather conditions from the middle of the day (around noon, 11-13 hours) for better representation
    • Returns up to 7 days of forecast data
  4. Backward Compatibility: The transformation layer ensures the widget's existing UI components continue to work without modification, as the transformed data structure matches the expected format.

  5. Error Handling: Enhanced error handling to validate the API response structure and provide meaningful error messages if the forecast data is missing or malformed.

Error message that is now fixed:

Error message with a working API key (One Call 2 5)

….5 API seems to not be working and ignore macOS metadata files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant