TC2-BBS-mesh/weather_plugin/command_router.py
default 4ac47e84bf Update weather plugin and enhance command handling
- Added weather plugin with functionality to fetch and display weather information using the OpenWeather API.
- Integrated weather command into the main menu and updated command handlers to manage user interactions for weather queries.
- Updated .gitignore to include database and configuration files.
- Created a test client for interactive testing of the BBS system.
- Added example configuration for the weather plugin.
2025-04-03 19:13:40 +00:00

29 lines
No EOL
1.2 KiB
Python

from utils import send_message, update_user_state
from .weather import get_weather_by_zip, format_weather_response
def handle_weather_command(sender_id, interface):
"""Handle the weather command from the main menu."""
response = "🌡️ Weather Service 🌡️\n\nEnter a ZIP code (89115) to get the current weather, or 'X' to exit:"
send_message(response, sender_id, interface)
update_user_state(sender_id, {'command': 'WEATHER', 'step': 1})
def handle_weather_steps(sender_id, message, step, interface):
"""Handle the steps for getting weather information."""
message = message.strip().upper()
if message == 'X':
from command_handlers import handle_help_command
handle_help_command(sender_id, interface)
return
if step == 1:
if not message.isdigit() or len(message) != 5:
send_message("Please enter a valid 5-digit ZIP code, or 'X' to exit.", sender_id, interface)
return
weather_data = get_weather_by_zip(message)
response = format_weather_response(weather_data)
send_message(response, sender_id, interface)
from command_handlers import handle_help_command
handle_help_command(sender_id, interface)