Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

PythonbeginnercliAI generated

Weather CLI

Build a Python command-line tool that shows the current weather for any city: you type weather Bucharest and see the temperature, how it feels, wind and conditions. It uses the free Open-Meteo API, which needs no account. When the internet is down or the API fails, it shows the last weather it saved for that city, clearly marked with how old it is, instead of just an error. It also keeps a history of past readings in a CSV file, which pandas turns into a quick summary (the average, the lowest and the highest temperature). It's a practical first Python project: you'll learn calling web APIs with requests, reading JSON, command-line arguments with argparse, caching to a file, handling errors, and basic pandas.

Estimate
~8h
Steps
6
Completed by
0
Proposed by
codeseed.app

requests · argparse · pandas · Open-Meteo

Project roadmap

  1. 01

    Define the command

    ~1h

    Write README.md showing how the tool is used (weather CITY, weather CITY --history, weather --help) and exactly what it prints in each case, including when showing saved data. Create a virtual environment and install requests, pandas and pytest. Done when: README.md shows every command with example output.

  2. 02

    Find the city and get the weather

    ~1.5h

    Use argparse to read the city name. Call the Open-Meteo geocoding API to find the city's coordinates (show the matches and use the first, or say clearly when nothing is found), then call the forecast API for the current weather. Use a timeout on every request. Turn the weather code into words, such as light rain. Done when: weather Bucharest prints the current weather.

  3. 03

    Save and use the last result

    ~1.5h

    After every successful request, save the result for that city with the time to a JSON cache file. When a request fails (no internet, timeout or server error), load the saved result instead and print it with a warning such as Offline, showing data from 3 hours ago. If there's no saved result, print a clear error and exit with code 1. Done when: with the internet off, a city looked up before shows its saved weather with the warning.

  4. 04

    Keep a history with pandas

    ~1.5h

    Append every successful reading (time, city, temperature, wind, conditions) to history.csv. Add --history, which loads the file with pandas, filters it to the city, and prints the number of readings, the average, lowest and highest temperature, and the last 5 readings. Done when: after a few lookups, --history shows correct statistics.

  5. 05

    Handle edge cases

    ~1h

    Handle an empty city name, a city that doesn't exist, a broken cache or history file (start fresh and warn instead of crashing), and an API response missing fields. Make sure the program never shows a Python traceback to the user. Done when: each of these cases prints a friendly message.

  6. 06

    Test it

    ~1.5h

    Write pytest tests that replace the network calls with fakes (using monkeypatch or the responses library): a normal lookup, city not found, a timeout that falls back to the cache, no cache available, and history statistics on a small CSV. Done when: pytest passes without using the internet.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~8h · 6 steps

Tech stack

requestsargparsepandasOpen-Meteo