Data sources¶
Open-Meteo is the only source. It needs no API key; never add one. The URLs are in config.py.
| API | Module | URL constant |
|---|---|---|
| Forecast | services/open_meteo.py |
OPEN_METEO_BASE_URL |
| Air quality | services/air_quality.py |
AIR_QUALITY_BASE_URL |
| Geocoding (city search) | services/geocoding.py |
GEOCODING_BASE_URL |
Rules for API modules¶
- Pure functions. Build the URL, call
requests, return JSON orNone. Every input is an argument:fetch_current(lat, lon, unit). - Every request has a timeout:
REQUEST_TIMEOUTfromconfig.py, a short connect timeout (so a broken IPv6 route falls back to IPv4 quickly) andTIMEOUTfor the answer. - Every function logs and returns
Noneon failure, catchingrequests.RequestException. They never raise. - Every call is cached with
@cached. - Expose module functions or public methods; never call a
_privateone from another module. clear_cache()forgets cached responses;clear_cache(lat, lon)one place's.
Forecast¶
| Function | What it asks for |
|---|---|
fetch_current(lat, lon, unit) |
CURRENT_FIELDS: temperature, humidity, feels like, weather code, is_day, precipitation, pressure, wind speed and direction |
fetch_hourly(lat, lon, unit) |
HOURLY_FIELDS incl. dew point, precipitation probability, rain, showers, snowfall, visibility, UV index; timezone=auto |
fetch_daily(lat, lon, unit) |
DAILY_FIELDS: weather code, max/min temperature, sunrise, sunset, max UV, precipitation sum, max wind, max precipitation probability; timezone=GMT |
fetch_many(coords, unit) |
temperature, weather code and is_day for several "lat,lon" places in one request (the Locations list). Its cache is not cleared by clear_cache |
All requests use timeformat=unixtime.
Air quality¶
fetch_air_quality(lat, lon) returns the hourly US and European AQI, pollutants (PM10, PM2.5, CO, CO₂, NO₂, SO₂, ozone, dust, ammonia, methane) and six pollen types, from three days back to three ahead. Pollutant colours come from the WHO-based THRESHOLDS in config.py.
Geocoding¶
find_city(name, count) returns a list of dicts (name, country, state, region, latitude, longitude, timezone), an empty list for no match, or None when the request failed. None is not cached, so a retry reaches the network. The search dialog waits CITY_SEARCH_DELAY_MS after the last keypress, needs CITY_SEARCH_MIN_CHARS, fetches CITY_SEARCH_MAX_RESULTS at once (the API has no paging) and shows CITY_SEARCH_PAGE_SIZE at a time.
Time¶
Request timeformat=unixtime. Convert with datetime.fromtimestamp(ts, ZoneInfo(tz)) in the city's time zone, never naive datetime.now() / fromtimestamp(ts). Never assume the city is in the system time zone: use the selected city's timezone (services/selected_city.py, core/timezones.py).
Units¶
Imperial is requested from the API where supported (temperature_unit, wind_speed_unit). Pressure (hPa → inHg, HPA_TO_INHG) and visibility (m → km / miles) are converted by us, in the API layer, core/units.py or the store's model building, never in widgets.
Adding a field¶
- Add it to the request list in the API module.
- Add it to the model's annotations in
core/models.py. - If it gets a level, add a
classify_*function incore/levels.py(with a test). - Show it in a card.
Connectivity check¶
check_internet_connection() (services/network.py) opens a socket to 1.1.1.1:53 and only if that fails requests the home pages of a few well-known sites. The answer is cached for INTERNET_CACHE_TTL seconds unless forced. Nothing about the user is sent.
Privacy¶
Send nothing about the user to any service except the coordinates and city name a request needs. Log only coordinates and city names.