Skip to content

Add weather forecast module with OpenWeatherMap integration#35

Merged
vannu07 merged 11 commits intomainfrom
copilot/add-weather-forecast-module
Jan 1, 2026
Merged

Add weather forecast module with OpenWeatherMap integration#35
vannu07 merged 11 commits intomainfrom
copilot/add-weather-forecast-module

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 1, 2026

Weather Forecast Module - PR Review Feedback Addressed ✅

Summary

All PR review comments have been addressed with comprehensive improvements to error handling, testing, and code quality.

✅ Addressed PR Review Comments

1. README.md:418 - news_fetcher.py documentation

  • No action needed - news_fetcher.py already exists in the repository

2-3. weather_fetcher.py Error Handling (Comments 2656550174, 2656550189)

  • ✅ Modified fetch_current_weather() to return tuple (data, error) instead of printing errors
  • ✅ Modified fetch_forecast() to return tuple (forecast_list, error) instead of printing errors
  • ✅ Updated all calling code in backend/feature.py to properly handle returned errors
  • ✅ Voice feedback now provides meaningful error messages to users

4. backend/command.py:92 - Fragile City Parsing (Comment 2656550175)

  • ✅ Replaced fragile chained replace() calls with robust regex-based parsing
  • ✅ New logic correctly handles cities with "weather" or "forecast" in their names (e.g., "Weatherford, Texas")
  • ✅ Uses regex \b(?:in|for)\s+(.+) to extract city names after prepositions
  • ✅ Falls back to removing command words only when prepositions aren't found

5-6. backend/feature.py - WeatherFetcher Instantiation (Comments 2656550179, 2656550182)

  • ✅ Created module-level _weather_fetcher variable with lazy initialization
  • ✅ Implemented get_weather_fetcher() helper function for reusable instance
  • ✅ Both get_weather() and get_weather_forecast() now reuse the same instance
  • ✅ Eliminates unnecessary object creation overhead

7. testing/weather_test.py - Proper Testing Framework (Comment 2656550183)

  • ✅ Replaced manual integration test with proper unittest framework
  • ✅ Added comprehensive mocking using unittest.mock for API responses
  • ✅ Tests now run without requiring API credentials or network access
  • ✅ Added 11 unit tests covering:
    • API key validation
    • Successful weather/forecast fetches with mocked responses
    • Error handling (404, network errors, invalid responses)
    • Formatting functions with various data types

8. weather_fetcher.py:28-31 - API Key Validation (Comment 2656550184)

  • ✅ Added validation in __init__() to ensure API key is set and non-empty
  • ✅ Raises ValueError with clear message when API key is missing/empty
  • ✅ Strips whitespace from API key before storing

9. weather_fetcher.py:46 - Wind Speed Precision (Comment 2656550185)

  • ✅ Changed wind speed from round(speed * 3.6, 1) to round(speed * 3.6)
  • ✅ Now rounds to whole number for consistency with temperature values

10. weather_fetcher.py:186 - Docstring Accuracy (Comment 2656550190)

  • ✅ Updated docstring from "Standalone usage example for testing" to "Interactive CLI demo"
  • ✅ Accurately describes the __main__ block functionality

11. backend/feature.py:317 - Forecast "Today" Assumption (Comment 2656550192)

  • ✅ Changed from "Today:" to "On the first day of the forecast:"
  • ✅ Avoids timezone confusion between user and API server
  • ✅ More accurate description of forecast data

📊 Changes Summary

  • Files Modified: 4 files (backend/command.py, backend/feature.py, testing/weather_test.py, weather_fetcher.py)
  • Lines Changed: +273, -95
  • New Unit Tests: 11 comprehensive tests with mocking
  • Issues Fixed: All 11 PR review comments addressed

✅ Testing

  • All unit tests pass (11/11)
  • Error handling verified with mock API responses
  • City name parsing tested with edge cases
  • No regressions in existing functionality
Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature] Add Weather Forecast Module</issue_title>
<issue_description>Enhance Jarvis with a feature that fetches and displays weather updates for any city.
Tasks:

  • Integrate with OpenWeatherMap API (free tier).
  • Fetch temperature, humidity, condition, and forecast for 3–5 days.
  • Handle invalid city inputs gracefully.
  • Display results in a clean console/GUI format.
  • Add example usage in README.
  • Write minimal test cases for this module.

</issue_description>

Comments on the Issue (you are @copilot in this section)

@vannu07 Thanks for offering to help, @Arihant2312 I've assigned you this feature. Let me know if you have any questions as you get started @vannu07 @Arihant2312 any update in this

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: vannu07 <161148074+vannu07@users.noreply.github.com>
Copilot AI and others added 2 commits January 1, 2026 18:51
Co-authored-by: vannu07 <161148074+vannu07@users.noreply.github.com>
Co-authored-by: vannu07 <161148074+vannu07@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds a weather forecast module to the Jarvis voice assistant, integrating with the OpenWeatherMap API to provide real-time weather updates and multi-day forecasts. The implementation includes a standalone weather fetcher module, voice command integration, configuration management for API keys, and documentation updates.

Key changes:

  • New weather fetching module with current weather and 5-day forecast capabilities
  • Voice command handlers for weather queries with city name extraction
  • Configuration support for OpenWeatherMap API key
  • Comprehensive README documentation with usage examples and setup instructions

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
weather_fetcher.py Core weather module implementing OpenWeatherMap API integration with current weather and forecast fetching, including error handling and formatting functions
testing/weather_test.py Manual integration tests for weather functionality requiring live API credentials
backend/feature.py Added get_weather and get_weather_forecast functions with voice response integration
backend/command.py Extended command parser to recognize and route weather/forecast queries
backend/config_manager.py Added openweathermap_api_key property to configuration manager
backend/config.py Exposed OPENWEATHERMAP_API_KEY constant for use throughout the application
README.md Added weather feature documentation including setup instructions, usage examples, and feature list

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md Outdated
Comment thread weather_fetcher.py Outdated
Comment on lines +49 to +60
except requests.exceptions.HTTPError as e:
if e.response.status_code == 404:
print(f"City '{city}' not found.")
else:
print(f"HTTP error: {e}")
return None
except requests.exceptions.RequestException as e:
print(f"Network error: {e}")
return None
except KeyError as e:
print(f"Unexpected API response format: {e}")
return None
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

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

Error messages are printed directly to console rather than being returned to the caller. This makes it difficult to properly handle errors in the integration with the voice assistant, as the calling code in backend/feature.py cannot distinguish between different error types (network error vs. invalid city vs. API format issue). Consider returning error information that the caller can handle appropriately, especially for voice feedback.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Comment thread backend/command.py Outdated
from backend.feature import get_weather, get_weather_forecast

# Extract city name from query
city = query.replace("weather", "").replace("forecast", "").replace("in", "").replace("for", "").strip()
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

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

The command parsing logic is fragile. Using multiple chained replace() calls can lead to incorrect parsing. For example, "weather forecast in paris" would have both "weather" and "forecast" removed, making it ambiguous. Additionally, if a city name contains these words (e.g., "Weatherford, Texas" or "Forecast, Australia"), they would be incorrectly stripped. Consider using a more robust parsing approach with regex or the existing parse_command function from backend.nlp.command_parser.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Comment thread backend/feature.py Outdated
Comment on lines +272 to +278
from weather_fetcher import WeatherFetcher

if not OPENWEATHERMAP_API_KEY:
speak("Weather API key is not configured. Please set OPENWEATHERMAP_API_KEY in your environment.")
return

fetcher = WeatherFetcher(OPENWEATHERMAP_API_KEY)
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

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

The WeatherFetcher is instantiated on every call to get_weather and get_weather_forecast. This is inefficient as the fetcher only holds the API key and could be reused. Consider creating a module-level instance of WeatherFetcher that's initialized once, similar to how other features in the file might handle their dependencies.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Comment thread backend/feature.py Outdated
Comment on lines +303 to +309
from weather_fetcher import WeatherFetcher

if not OPENWEATHERMAP_API_KEY:
speak("Weather API key is not configured. Please set OPENWEATHERMAP_API_KEY in your environment.")
return

fetcher = WeatherFetcher(OPENWEATHERMAP_API_KEY)
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

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

The WeatherFetcher is instantiated again here, duplicating the instantiation pattern from get_weather. This creates unnecessary object creation overhead and makes the code harder to maintain if the initialization logic needs to change. Consider creating a shared instance or a helper function to get the fetcher instance.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Comment thread weather_fetcher.py
Comment on lines +28 to +31
params = {
"q": city,
"appid": self.api_key,
"units": "metric" # Use Celsius
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

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

The API key is passed directly in URL parameters without any validation or sanitization. While this follows the OpenWeatherMap API specification, consider adding validation to ensure the API key is set and non-empty before making requests. This would provide clearer error messages when the API key is misconfigured rather than getting cryptic API errors.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Comment thread weather_fetcher.py Outdated
Comment thread weather_fetcher.py Outdated
Comment on lines +124 to +135
except requests.exceptions.HTTPError as e:
if e.response.status_code == 404:
print(f"City '{city}' not found.")
else:
print(f"HTTP error: {e}")
return None
except requests.exceptions.RequestException as e:
print(f"Network error: {e}")
return None
except KeyError as e:
print(f"Unexpected API response format: {e}")
return None
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

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

The same error handling pattern with console prints is repeated here. Error messages are printed directly rather than being returned to the caller. This duplicates the error handling issue from fetch_current_weather and makes the code harder to maintain. Consider extracting common error handling logic into a helper method that returns structured error information.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Comment thread weather_fetcher.py Outdated
Comment thread backend/feature.py Outdated
Co-authored-by: vannu07 <161148074+vannu07@users.noreply.github.com>
@vannu07
Copy link
Copy Markdown
Owner

vannu07 commented Jan 1, 2026

@copilot apply changes based on the comments in this thread

Copilot AI changed the title [WIP] Add weather forecast module to enhance Jarvis Add weather forecast module with OpenWeatherMap integration Jan 1, 2026
Copilot AI requested a review from vannu07 January 1, 2026 18:57
@vannu07 vannu07 marked this pull request as ready for review January 1, 2026 18:58
vannu07 and others added 6 commits January 2, 2026 00:28
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ting

Co-authored-by: vannu07 <161148074+vannu07@users.noreply.github.com>
Co-authored-by: vannu07 <161148074+vannu07@users.noreply.github.com>
@vannu07 vannu07 merged commit 9e96820 into main Jan 1, 2026
1 check passed
@vannu07 vannu07 deleted the copilot/add-weather-forecast-module branch January 1, 2026 19:06
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.

[Feature] Add Weather Forecast Module

3 participants