How cgmafia/weatherindexer works
Purpose and Entry Points
A small Python/Flask REST API that evaluates a requested city’s weather against an index/rival city (default described as Cologne). It returns a JSON check result plus individual criteria outcomes.
• HTTP application entry point: api.py
• Weather/domain logic: weather.py
• Runtime dependencies: requirements.txt
API Surface
api.py starts the Flask server and exposes the documented routes:
• /: base endpoint
• /check: evaluate using configured/default city behavior
• /check?city=cityname: evaluate a caller-supplied city
The HTTP layer is responsible for request parsing and JSON response construction; weather comparison behavior belongs behind it in weather.py.
Weather Provider Boundary
The service calls OpenWeatherMap through configuration supplied in a root .env file:
• OpenWeatherAPI: provider URL
• API_KEY: provider credential
• INDEX_CITY: baseline city
This creates an external-network boundary: weather.py should isolate provider requests, response interpretation, and failures from Flask route handling.
Evaluation Pipeline
The central flow is:
1. Receive optional city from /check in api.py.
2. Resolve the requested city and configured index city.
3. Retrieve current weather data from OpenWeatherMap.
4. Apply comparison criteria in weather.py.
5. Return criteria flags and aggregate them as check.
The documented response contains daytemp, naming, and rival criteria, with top-level check representing the overall decision.
Core Domain Components
• Flask API/controller — process lifecycle, route dispatch, query parameters, and JSON response: api.py.
• Weather client/domain evaluator — OpenWeatherMap access and comparison rules such as temperature, naming, and rival evaluation: weather.py.
• Environment-driven provider configuration — endpoint, API key, and baseline city supplied outside source code; consumed by the application rooted at api.py and weather.py.
• Automated validation boundary — behavior is exercised through pytest: test_all.py.
Runtime and Infrastructure
The service requires Python 3.9+, Flask, and pytest, with package installation defined in requirements.txt. It runs as a local Flask process via python api.py, listens on the documented localhost endpoints, and depends on the OpenWeatherMap current-weather API plus a valid API key.
Main entry points: weather.py Weather evaluator · api.py HTTP routes · requirements.txt Python dependencies · test_all.py Pytest validation
Components 10
Runtime
- Flask process · Started with python api.py.
api.py - Environment configuration · Provides OpenWeatherAPI, API_KEY, and INDEX_CITY.
- Python dependencies · Defines Flask, pytest, and runtime packages.
requirements.txt - Pytest validation · Exercises API behavior.
test_all.py
Application
- HTTP routes · Serves / and /check, including the city query parameter.
api.py - JSON response · Returns check plus daytemp, naming, and rival outcomes.
api.py - Weather evaluator · Resolves cities and applies weather comparison rules.
weather.py - Comparison criteria · Evaluates daytemp, naming, rival, and aggregate check.
weather.py - Weather provider client · Isolates provider requests, response interpretation, and failures.
weather.py
External services
- OpenWeatherMap
Connections 11
- Python dependencies → Flask process: installs runtime
- Flask process → HTTP routes: dispatches
- HTTP routes → Weather evaluator: passes optional city
- Weather evaluator → Weather provider client: retrieves weather
- Weather evaluator → Comparison criteria: applies
- Comparison criteria → JSON response: criteria and check
- JSON response → HTTP routes: JSON result
- Environment configuration → Weather evaluator: INDEX_CITY
- Environment configuration → Weather provider client: URL and API key
- Weather provider client → OpenWeatherMap: current-weather request
- Pytest validation → HTTP routes: validates behavior