#!/usr/bin/env python3 """ weather - Quick weather check Get current weather and forecasts using wttr.in. """ import sys import subprocess from pathlib import Path WORKSPACE = Path("/home/wdjones/.openclaw/workspace") DEFAULT_LOCATION = "auto" # wttr.in auto-detects def get_weather(location: str = None, detailed: bool = False): """Get weather for a location.""" loc = location or DEFAULT_LOCATION loc = loc.replace(' ', '+') if detailed: # Full forecast cmd = f'curl -s "wttr.in/{loc}?T"' else: # Compact format cmd = f'curl -s "wttr.in/{loc}?format=%l:+%c+%t+%h+%w"' result = subprocess.run(cmd, shell=True, capture_output=True, text=True) output = result.stdout.strip() if 'Unknown location' in output: print(f"Location not found: {location}") return print(output) def get_moon(): """Get moon phase.""" cmd = 'curl -s "wttr.in/moon"' result = subprocess.run(cmd, shell=True, capture_output=True, text=True) print(result.stdout) def main(): if len(sys.argv) < 2: # Default: compact weather for auto location get_weather() return cmd = sys.argv[1] if cmd == 'moon': get_moon() elif cmd == 'full': location = ' '.join(sys.argv[2:]) if len(sys.argv) > 2 else None get_weather(location, detailed=True) elif cmd in ['-h', '--help']: print("Usage:") print(" weather - Current weather (auto location)") print(" weather - Weather for location") print(" weather full [loc] - Detailed forecast") print(" weather moon - Moon phase") print("") print("Examples:") print(" weather London") print(" weather 'New York'") print(" weather full Chicago") else: # Treat as location location = ' '.join(sys.argv[1:]) get_weather(location) if __name__ == "__main__": main()