Skip to content

Conversation

@clayauld
Copy link
Owner

@clayauld clayauld commented Oct 8, 2025

Migrate the SatCom forecast system from web scraping to the NWS API to improve reliability, data quality, and maintainability.

The previous web scraping implementation was fragile and prone to breakage due to changes in the target website's HTML structure. This migration to the official Weather.gov API provides a stable, structured data source, along with robust error handling, caching, and a hybrid mode for a smooth transition, ensuring long-term stability and better data accuracy.


Open in Cursor Open in Web


Note

Migrate SatCom Forecast to Weather.gov API with hybrid fallback, caching, robust error handling, updated parsing/formatting, and comprehensive tests/CI tooling.

  • Backend/API:
    • Introduce Weather.gov API stack: api_client.py, api_models.py, api_data_processor.py, api_formatter.py, api_cache.py, api_error_handler.py, api_config.py, and forecast_fetcher_api.py (hybrid API/HTML, caching, rate limiting, retries, circuit breaker).
    • Update coordinator.py to use new fetch_forecast (hybrid) and improve logging and config handling.
  • Parsing/Formatting:
    • Enhance forecast_parser.py (expanded valid period names incl. holidays, probability/context parsing, wind/temp extraction, summary/compact/full formatting consistency).
    • Add shared utilities in weather_utils.py for event detection, chance inference, wind/temp extraction, and day filtering.
  • IMAP/Email:
    • Harden imap_handler.py (robust decoding, folder handling, days override) and type-safety improvements in notifier.py.
  • Config/Migration:
    • Adjust __init__.py entry migration (v2→v3, v3→v4) and debug service.
  • Tooling/CI:
    • Add extensive tests and fixtures under tests/ plus scripts (scripts/run_api_tests.py, discovery/connectivity).
    • Update GitHub Actions: testing/linting (add Bandit), artifact upload v4, permissions; Makefile test targets; pre-commit; pyproject.toml/requirements.txt.
    • Replace issue templates with structured YAML.
  • Docs:
    • Add API migration docs, HA testing guide, contributing and testing/linting strategy.

Written by Cursor Bugbot for commit 5b81d1f. This will update automatically on new commits. Configure here.

This commit introduces a new Weather.gov API client, data processing, formatting, caching, and error handling modules. It replaces the previous HTML scraping method with a more robust and reliable API-based approach. The changes include:

- **New API Modules**: `api_client`, `api_config`, `api_models`, `api_data_processor`, `api_formatter`, `api_cache`, `api_error_handler`.
- **Enhanced Fetcher**: `forecast_fetcher_api.py` provides a hybrid mode supporting both API and HTML fallback.
- **Configuration**: Environment variables and feature flags for flexible control.
- **Caching**: Implemented for improved performance and reduced API calls.
- **Error Handling**: Comprehensive framework with retry logic and circuit breaker.
- **Testing**: New unit, integration, and compatibility tests added.
- **Documentation**: Updated READMEs and examples.

The `fetch_forecast` function is updated to use the new API-based implementation automatically, ensuring backward compatibility.

Co-authored-by: clayton <clayton@clayauld.com>
@cursor
Copy link

cursor bot commented Oct 8, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@clayauld clayauld marked this pull request as ready for review October 8, 2025 21:35
cursoragent and others added 3 commits October 8, 2025 21:45
Co-authored-by: clayton <clayton@clayauld.com>
This commit enhances the testing framework by replacing the previous test execution method with `pytest` for improved test management and reporting. It also updates the API integration to include new features such as:

- Transition from manual test scripts to `pytest` for running tests.
- Improved error handling in the API client, including better response validation.
- Added new test cases for API functionality, ensuring comprehensive coverage of edge cases.
- Introduced a new logo asset for branding purposes.

Additionally, the `pytest.ini` configuration has been updated to reflect the new testing structure and added markers for better test categorization.

Co-authored-by: clayton <clayton@clayauld.com>
Repository owner deleted a comment from github-actions bot Nov 26, 2025
Repository owner deleted a comment from github-actions bot Nov 26, 2025
@github-actions
Copy link

github-actions bot commented Nov 26, 2025

📊 Pull Request Analysis Report

🧪 Test Results

Metric Value
Total Tests 244
✅ Passed 244
❌ Failed 0
⏭️ Skipped 0
💥 Errors 0
📈 Success Rate 100.0%

📋 Coverage Report

Metric Value
Overall Coverage 81.6%
Total Lines 2791
Covered Lines 2277
Missing Lines 514

📁 File Coverage Breakdown

  • __init__.py: 86.5%
  • api_cache.py: 83.5%
  • api_client.py: 84.5%
  • api_config.py: 75.2%
  • api_data_processor.py: 78.9%
  • api_error_handler.py: 88.9%
  • api_formatter.py: 94.2%
  • api_models.py: 94.7%
  • config_flow.py: 68.5%
  • const.py: 100.0%

🎯 Recommendations


📊 Analysis generated by GitHub Actions • View detailed test report

@clayauld

This comment was marked as resolved.

cursor[bot]

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

clayauld and others added 3 commits November 26, 2025 00:55
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…ub.com:clayauld/satcom-forecast into cursor/migrate-satcom-forecast-to-nws-api-dee5
…text and add tests for multiple percentage scenarios.
@clayauld

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

…"Today" and refactor period filtering to weather utilities.
@clayauld

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

clayauld and others added 2 commits November 26, 2025 10:35
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…r handling, and refine text splitting logic.
…ub.com:clayauld/satcom-forecast into cursor/migrate-satcom-forecast-to-nws-api-dee5
…t.toml for mypy settings; refactor type hints and method signatures across various components for consistency and clarity.
Repository owner deleted a comment from github-actions bot Nov 26, 2025
Repository owner deleted a comment from github-actions bot Nov 26, 2025
…factor logging messages for improved readability across various components.
@github-actions

This comment was marked as resolved.

…e forecast div validation in fetch_forecast function
…hance pytest settings in pyproject.toml, and add Bandit security checks to CI workflow; consolidate testing and linting strategy documentation.
@clayauld
Copy link
Owner Author

/gemini review

…ests; replace with updated YAML configurations for improved clarity and user guidance.
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is an excellent and comprehensive pull request that successfully migrates the forecast fetching mechanism from fragile web scraping to the robust NWS API. The new architecture is well-designed, incorporating best practices like caching, robust error handling with retries and circuit breakers, and clear separation of concerns with new modules for the API client, data processing, and configuration. The inclusion of a hybrid mode for a smooth transition is a thoughtful touch. The code quality is high, and the addition of extensive documentation and tests is commendable. I have a couple of suggestions for refactoring to improve maintainability and robustness, but overall, this is a fantastic contribution.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@clayauld clayauld merged commit 8110042 into main Nov 27, 2025
10 checks passed
@clayauld clayauld deleted the cursor/migrate-satcom-forecast-to-nws-api-dee5 branch November 27, 2025 03:48
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.

2 participants