Weather Cli
TUTOR WITH THEFOCUS.AI
Copy this prompt into Claude, ChatGPT, or any external AI assistant. It points the assistant to the course instructions and links it to your student profile to track your progress and customize observations.
You are not enrolled yet. Enroll to generate a Student ID to track lesson completions and store learning notes.
Project: Weather CLI
Source: 0-weather/
Model: gemma4:26b
Type: Bash script
The Prompt
write a bash script that uses wget to get the weather in new york city
That’s it. One sentence. No clarifying questions, no spells — just a straightforward request.
The Model’s Reasoning
The model immediately recognized that wget alone can’t render a weather webpage. It considered three options:
- wttr.in (chosen) — designed specifically for CLI weather, returns plain text
- Weather APIs (rejected) — requires API keys, adds friction
- Scraping a site (rejected) — fragile and difficult with just
wget
It settled on wttr.in with the ?format=3 parameter for a single-line summary, then added error handling for missing wget and failed downloads.
The Code
#!/bin/bash
# Define the location (New York City)
# Use underscores instead of spaces for the URL
LOCATION="New_York"
# The URL for the weather service
# wttr.in is a great service that provides terminal-friendly output
URL="https://wttr.in/${LOCATION}?format=3"
# Check if wget is installed
if ! command -v wget &> /dev/null; then
echo "Error: 'wget' is not installed. Please install it to use this script."
exit 1
fi
echo "--- Fetching Weather for $LOCATION ---"
# Use wget to fetch the data
# -q: quiet mode (hides download progress)
# -O-: sends the downloaded content to 'stdout' (the terminal) instead of a file
WEATHER_DATA=$(wget -qO- "$URL")
# Check if the download was successful
if [ $? -eq 0 ]; then
echo "$WEATHER_DATA"
else
echo "Error: Failed to retrieve weather data. Check your internet connection."
exit 1
fi
echo "---------------------------------------"
How to Run
chmod +x 0-weather/code
./0-weather/code
Or install it as a system command:
sudo mv 0-weather/code /usr/local/bin/weather
weather
How to Customize
Change the LOCATION variable to any city:
LOCATION="Tokyo"
LOCATION="London"
LOCATION="San_Francisco" # use underscores for spaces
For a full ASCII-art weather report instead of a one-liner, remove the ?format=3 from the URL:
URL="https://wttr.in/${LOCATION}"
Key Lessons
- The model knows about APIs. It recognized
wttr.inas the right tool for CLI weather without being told. - Simple prompts can work when the task is well-defined and the solution space is narrow.
- Error handling matters even in tiny scripts — checking for
wgetand failed downloads makes it robust. - The model adds polish. A one-sentence prompt produced commented, error-handled, production-ready bash.
Next: File Combiner →