| name | weather |
| description | Get weather information using system commands and offline methods without external APIs. Use when you need weather data and want to avoid API dependencies. |
Important Note
Weather data typically requires external APIs for accurate, real-time information. This skill provides methods to get weather without APIs using system commands, offline databases, and local sources. For accurate weather, consider using free weather APIs (OpenWeatherMap, WeatherAPI, etc.).
When to Use
- Getting weather from system commands
- Parsing weather from local files
- Using offline weather databases
- Displaying cached weather data
- When API access is restricted
System Commands
Linux/Unix (weather-util)
sudo apt-get install weather-util
weather "New York"
weather "KJFK"
weather -m "London"
weather -f "Paris"
Linux/Unix (weget)
sudo apt-get install weget
weget "Tokyo"
macOS (weather-cli)
brew install weather-cli
weather "San Francisco"
weather -f "Los Angeles"
Windows (PowerShell)
# Using built-in weather (Windows 10/11)
# Note: This may require specific Windows versions
# Alternative: Use curl to fetch from weather sites
curl "https://wttr.in/New_York"
wttr.in (No API Key Required)
wttr.in is a free weather service that doesn't require an API key and can be used via curl/wget:
curl "https://wttr.in/New_York"
curl "https://wttr.in/New_York?format=3"
curl "https://wttr.in/New_York?format=1"
curl "https://wttr.in/New_York?format=j1"
curl "https://wttr.in/New_York?m"
curl "https://wttr.in/New_York?0"
JavaScript Example
const https = require('https');
function getWeather(city) {
return new Promise((resolve, reject) => {
const url = `https://wttr.in/${encodeURIComponent(city)}?format=j1`;
https.get(url, (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
try {
const weather = JSON.parse(data);
resolve(weather);
} catch (error) {
reject(error);
}
});
}).on('error', reject);
});
}
getWeather('New York').then(weather => {
console.log(`Temperature: ${weather.current_condition[0].temp_C}°C`);
console.log(`Condition: ${weather.current_condition[0].weatherDesc[0].value}`);
});
Python Example
import requests
import json
def get_weather(city):
url = f"https://wttr.in/{city}?format=j1"
response = requests.get(url)
return response.json()
weather = get_weather("New York")
current = weather['current_condition'][0]
print(f"Temperature: {current['temp_C']}°C")
print(f"Condition: {current['weatherDesc'][0]['value']}")
Offline Weather Databases
Using Historical Weather Data
import csv
from datetime import datetime
def get_historical_weather(city, date):
with open('weather_database.csv', 'r') as f:
reader = csv.DictReader(f)
for row in reader:
if row['city'] == city and row['date'] == date:
return {
'temperature': row['temp'],
'condition': row['condition'],
'humidity': row['humidity']
}
return None
Weather.gov (US Only, No API Key)
import requests
def get_us_weather(lat, lon):
url = f"https://api.weather.gov/points/{lat},{lon}"
response = requests.get(url)
data = response.json()
forecast_url = data['properties']['forecast']
forecast = requests.get(forecast_url).json()
return forecast
Parsing Weather from Files
JSON Weather File
{
"city": "New York",
"temperature": 72,
"condition": "Sunny",
"humidity": 45,
"updated": "2025-04-30T09:00:00Z"
}
const fs = require('fs');
const weather = JSON.parse(fs.readFileSync('weather.json', 'utf8'));
console.log(`Weather in ${weather.city}: ${weather.temperature}°F, ${weather.condition}`);
XML Weather File
import xml.etree.ElementTree as ET
def parse_weather_xml(file_path):
tree = ET.parse(file_path)
root = tree.getroot()
return {
'city': root.find('city').text,
'temperature': root.find('temperature').text,
'condition': root.find('condition').text
}
System Weather Widgets
macOS
system_profiler SPDisplaysDataType
Linux
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "Main.panel.statusArea.aggregateMenu._weather._item._weatherInfo"
Caching Weather Data
class WeatherCache {
constructor(cacheFile = 'weather_cache.json') {
this.cacheFile = cacheFile;
this.cache = this.loadCache();
}
loadCache() {
try {
const fs = require('fs');
const data = fs.readFileSync(this.cacheFile, 'utf8');
return JSON.parse(data);
} catch {
return {};
}
}
saveCache() {
const fs = require('fs');
fs.writeFileSync(this.cacheFile, JSON.stringify(this.cache, null, 2));
}
get(city) {
const cached = this.cache[city];
if (cached) {
const age = Date.now() - cached.timestamp;
if (age < 3600000) {
return cached.data;
}
}
return null;
}
set(city, data) {
this.cache[city] = {
data: data,
timestamp: Date.now()
};
this.saveCache();
}
}
Best Practices
- Cache weather data to avoid repeated requests
- Use wttr.in for simple no-API weather needs
- Consider local weather databases for offline access
- Handle network errors gracefully
- Provide fallback data when APIs are unavailable
- Respect rate limits even for free services
- Use appropriate units (metric vs imperial)
- Handle timezone conversions for timestamps
Limitations
- No-API weather methods have limited accuracy
- System commands may not be available on all platforms
- Offline data requires regular updates
- wttr.in may have rate limits
- Weather.gov only works for US locations
- Cached data becomes stale over time
When to Use Real Weather APIs
For accurate, real-time weather data, consider these free APIs:
- OpenWeatherMap: Free tier available
- WeatherAPI: Free tier with limited calls
- AccuWeather: Free tier available
- NOAA: Free for US weather data
These provide:
- Real-time data
- Forecasts
- Historical data
- Global coverage
- Higher accuracy
Scripts
get-weather.sh
#!/bin/bash
CITY="${1:-New York}"
echo "Fetching weather for $CITY..."
curl -s "https://wttr.in/$CITY?format=3"
if command -v weather &> /dev/null; then
weather "$CITY"
fi
get-weather.py
import sys
import requests
def get_weather(city):
try:
response = requests.get(f"https://wttr.in/{city}?format=j1")
data = response.json()
current = data['current_condition'][0]
area = data['nearest_area'][0]
print(f"Weather in {area['areaName'][0]['value']}, {area['country'][0]['value']}")
print(f"Temperature: {current['temp_C']}°C ({current['temp_F']}°F)")
print(f"Condition: {current['weatherDesc'][0]['value']}")
print(f"Humidity: {current['humidity']}%")
print(f"Wind: {current['windspeedKmph']} km/h")
except Exception as e:
print(f"Error fetching weather: {e}")
if __name__ == '__main__':
city = sys.argv[1] if len(sys.argv) > 1 else "New York"
get_weather(city)