A command-line tool that fetches and displays data from a public web API. You'll build a weather lookup tool using the free Open-Meteo API (no API key required) that shows current weather for any city.
- HTTP requests with the
requestslibrary - JSON parsing and data extraction
- argparse for CLI interface
- Error handling (network errors, bad responses, missing data)
- String formatting for readable output
- Accept a city name from the command line
- Look up the city's coordinates using the Open-Meteo geocoding API
- Fetch current weather data for those coordinates
- Display temperature, wind speed, and weather description
- Handle errors gracefully (city not found, network issues)
- Add a
--forecastflag to show multi-day forecast - Add
--unitsflag (metric/imperial) - Cache results to avoid repeated API calls
- Support multiple cities in one command
- Add colored output based on temperature
$ python3 starter.py London
Weather for London, United Kingdom:
Temperature: 12.3°C
Wind speed: 15.2 km/h
Condition: Partly cloudy
$ python3 starter.py "New York"
Weather for New York, United States:
Temperature: 8.1°C
Wind speed: 22.4 km/h
Condition: Overcast
$ python3 starter.py Nowhereville
Error: City 'Nowhereville' not found.Both APIs are free and require no API key.
Geocoding (city name → coordinates):
https://geocoding-api.open-meteo.com/v1/search?name=London&count=1
Weather (coordinates → current weather):
https://api.open-meteo.com/v1/forecast?latitude=51.5&longitude=-0.1¤t_weather=true
requests.get(url, params={...})is cleaner than building URL strings manually- Check
response.status_codeor useresponse.raise_for_status() - The geocoding API returns a
resultslist — take the first match - Weather codes (0=clear, 1-3=cloudy, etc.) need to be mapped to descriptions
- Use
try/except requests.RequestExceptionfor network errors - Install requests with:
pip install requests
starter.py— skeleton code with function signatures and structuresolution.py— complete working implementation