Project: Weather Data Fetcher0%

Project: Weather Data Fetcher

Beginner12 min readUpdated: Jul 11, 2026
Study Materials

Project: Weather Data Fetcher

In this hands-on project, we will apply the HTTP networking concepts covered throughout this chapter—HTTP Requests, Query Parameters, JSON Parsing, and Network Exception Handling—to build a functional, real-time Command-Line Weather Data Fetcher.

We will connect to the open, free Open-Meteo API (which requires zero API keys or credit cards) to look up city coordinates and fetch current meteorological telemetry.


1. System Architecture & API Endpoints

Our weather application performs a two-stage API pipeline:

  1. 1
    Geocoding API: Resolves a user's textual city query (e.g. "Mumbai" or "London") into exact latitude and longitude coordinates.
  • Endpoint: https://geocoding-api.open-meteo.com/v1/search?name={city}&count=1
  1. 1
    Forecast Weather API: Fetches current weather telemetry for those coordinates.
  • Endpoint: https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lng}&current_weather=true
  1. 1
    Data Translation Layer: Maps numerical WMO weather codes (e.g. Code 0 = "Clear Sky", Code 61 = "Slight Rain") to user-friendly status descriptions.

2. Complete Application Code

Visual Architecture & Process Flow

How data and code flow step-by-step

Flowchart
Step 1
def get_coordinates
self, city_name: str
Step 2
Optional[Tuple[float, float, str, str]]:

3. Sample Execution Simulation

Output
==================================================
REAL-TIME GLOBAL WEATHER DASHBOARD
==================================================
 
Enter city name (or 'quit' to exit): New Delhi
 
Searching coordinates for 'New Delhi'...
 
==================================================
WEATHER REPORT: NEW DELHI, INDIA ☀️
==================================================
Coordinates : 28.61°N, 77.21°E
Condition : Clear sky
Temperature : 31.4°C (88.5°F)
Wind Speed : 8.2 km/h
Wind Direction : 295°
==================================================
 
Enter city name (or 'quit' to exit): London
 
Searching coordinates for 'London'...
 
==================================================
WEATHER REPORT: LONDON, UNITED KINGDOM 🌧️
==================================================
Coordinates : 51.51°N, -0.13°E
Condition : Slight rain
Temperature : 14.2°C (57.6°F)
Wind Speed : 19.8 km/h
Wind Direction : 210°
==================================================
 
Enter city name (or 'quit' to exit): quit
Thank you for using the Weather Dashboard. Stay safe!

Multiple Choice Questions

1. In this project, what is the role of the Geocoding API step?

A. To check whether the user has internet access B. To translate the human-readable city string into decimal latitude and longitude coordinates C. To generate an SVG weather icon D. To verify user credentials Answer: B Explanation: The Weather forecast API requires numerical latitude and longitude coordinates, so the geocoding service translates city names like "London" into 51.51 and -0.13.


2. Why is self.session = requests.Session() instantiated inside the WeatherFetcher constructor?

A. To encrypt terminal output B. To reuse TCP connections across the geocoding and forecast queries, improving performance C. To prevent the program from running on Windows D. To disable DNS lookups Answer: B Explanation: requests.Session() reuses underlying network sockets (HTTP keep-alive) across both calls, reducing network handshake latency.


3. What does WEATHER_CODES.get(code, ("Unknown", "❓")) do if an unlisted code is encountered?

A. Raises an unhandled KeyError B. Returns the fallback tuple ("Unknown", "❓") safely without crashing C. Makes another network request D. Halts Python execution Answer: B Explanation: The .get() method on dictionaries allows providing a default fallback value when the searched key is not present.


4. How does the application prevent hanging if the remote weather API is unresponsive?

A. By setting a default timeout parameter on all requests B. By creating background threads C. By relying on the operating system to terminate the terminal D. By calling sys.exit() after every call Answer: A Explanation: Supplying timeout=self.timeout to requests.get() guarantees the socket will raise a requests.exceptions.Timeout exception if the server doesn't respond within the time limit.


5. What method is called on the response object to confirm whether the HTTP status code was successful?

A. response.verify_success() B. response.raise_for_status() C. response.confirm() D. response.assert_status() Answer: B Explanation: response.raise_for_status() checks the status code and raises an HTTPError if the response represents a client or server failure (4xx or 5xx).


Next Lesson

Using print vs logging

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext