BuddAI/skills/weather.py
JamesTheGiblet f9fd27d228 Implement core skills: Code validation, model fine-tuning, and system diagnostics
- Added `ModelFineTuner` class for preparing training data and fine-tuning models based on user corrections.
- Introduced `CodeValidator` class to validate generated code against various hardware and style rules, including safety checks and function naming conventions.
- Developed skills for calculator operations, system information retrieval, weather fetching, and timer functionality.
- Implemented a self-diagnostic skill to run unit tests and report results.
- Created a dynamic skill loading mechanism to discover and register skills from the current directory.
- Added unit tests for skills to ensure functionality and reliability.
2026-01-06 22:04:37 +00:00

44 lines
No EOL
1.4 KiB
Python

import urllib.request
import urllib.parse
import re
def meta():
"""
Metadata for the Weather skill.
"""
return {
"name": "Weather",
"description": "Fetches current weather using wttr.in (no API key required).",
"triggers": ["weather", "temperature", "forecast"]
}
def run(payload):
"""
Fetches weather data.
"""
prompt = payload if isinstance(payload, str) else payload.get("prompt", "")
location = ""
# Extract location: "weather in London", "weather for Paris"
match = re.search(r'\b(?:in|for|at)\s+(.+)', prompt, re.IGNORECASE)
if match:
location = match.group(1).strip().rstrip("?.!")
try:
query = urllib.parse.quote(location) if location else ""
# format=3 gives a concise one-line output (e.g., "London: ⛅️ +13°C")
url = f"https://wttr.in/{query}?format=3"
req = urllib.request.Request(
url,
headers={'User-Agent': 'curl/7.68.0'} # Mimic curl to ensure text output
)
with urllib.request.urlopen(req, timeout=5) as response:
if response.status == 200:
result = response.read().decode('utf-8').strip()
return f"🌦️ {result}"
return f"❌ Weather error: {response.status}"
except Exception as e:
return f"❌ Failed to fetch weather: {str(e)}"