Port of wttr.in
  • Zig 83.9%
  • C 14.7%
  • Python 0.6%
  • CSS 0.6%
  • Makefile 0.1%
Find a file
Emil Lerch 5579cb53bb
All checks were successful
Generic zig build / build (push) Successful in 1m30s
Generic zig build / publish (push) Successful in 8s
Generic zig build / deploy (push) Successful in 11s
back to karlsequin http.zig
2026-11-21 09:22:07 -08:00
.forgejo/workflows upgrade to zig 0.17.1 2026-11-20 11:31:00 -08:00
build upgrade to zig 0.17.1 2026-11-20 11:31:00 -08:00
docker add ca-certificates for inclusion in docker image 2026-01-05 14:07:24 -08:00
libs remove png support 2026-08-04 16:19:37 -07:00
scripts remove left over dead shell script 2026-01-05 10:06:10 -08:00
src upgrade to zig 0.17.1 2026-11-20 11:31:00 -08:00
.gitignore add .tmp/ to gitignore 2026-08-04 16:55:15 -07:00
.mise.toml upgrade to zig 0.17.1 2026-11-20 11:31:00 -08:00
.pre-commit-config.yaml remove png support 2026-08-04 16:19:37 -07:00
.travis.yml travis: pyflake only bin and lib 2019-12-29 17:50:14 +01:00
ARCHITECTURE.md add admin api 2026-11-17 15:00:13 -08:00
build.zig upgrade to zig 0.17.1 2026-11-20 11:31:00 -08:00
build.zig.zon back to karlsequin http.zig 2026-11-21 09:22:07 -08:00
LICENSE Initial commit 2015-12-26 23:03:43 +02:00
MISSING_FEATURES.md remove png support 2026-08-04 16:19:37 -07:00
README.md add WTTR_PROXY_HOPS to harden the X-Forwarded-For behavior 2026-11-17 16:05:03 -08:00

wttr — console-oriented weather forecast service

wttr is a console-oriented weather forecast service written in Zig, based on wttr.in.

wttr supports various information representation methods like terminal-oriented ANSI-sequences for console HTTP clients (curl, httpie, or wget), and HTML for web browsers.

Usage

You can access the service from a shell or from a Web browser:

$ curl localhost:8002
Weather for City: Paris, France

     \   /     Clear
      .-.      10 – 11 °C
   ― (   ) ―   ↑ 11 km/h
      `-'      10 km
     /   \     0.0 mm

Or in PowerShell:

Invoke-RestMethod http://localhost:8002

Get weather for a specific location by adding it to the URL:

$ curl localhost:8002/London
$ curl localhost:8002/Moscow
$ curl localhost:8002/Salt+Lake+City

If you omit the location name, you'll get the report for your current location based on your IP address.

Use 3-letter airport codes to get weather at a specific airport:

$ curl localhost:8002/muc      # Munich International Airport
$ curl localhost:8002/ham      # Hamburg Airport

Look up special locations (attractions, mountains, etc.) by prefixing with ~:

$ curl localhost:8002/~Vostok+Station
$ curl localhost:8002/~Eiffel+Tower
$ curl localhost:8002/~Kilimanjaro

You can also use IP addresses or domain names (prefixed with @):

$ curl localhost:8002/@github.com
$ curl localhost:8002/@msu.ru

To get detailed information, access the help page:

$ curl localhost:8002/:help

Weather Units

By default the USCS units are used for the queries from the USA and the metric system for the rest of the world. You can override this behavior by adding ?u or ?m to a URL:

$ curl localhost:8002/Amsterdam?u  # USCS (used by default in US)
$ curl localhost:8002/Amsterdam?m  # metric (SI) (used by default everywhere except US)

One-line output

For one-line output format, specify the format parameter:

$ curl localhost:8002/Nuremberg?format=3
Nuremberg: 🌦 +11⁰C

Available preconfigured formats: 1, 2, 3, 4 and custom format using percent notation.

  • format=1: 🌦 +11⁰C
  • format=2: 🌦 🌡️+11°C 🌬️↓4km/h
  • format=3: Nuremberg: 🌦 +11⁰C
  • format=4: Nuremberg: 🌦 🌡️+11°C 🌬️↓4km/h

Note: Wttr.in claims that you can do multiple locations at one with a ':' separator, but that does not appear to work

$ curl localhost:8002/Nuremberg:Hamburg:Berlin?format=3
Nuremberg: 🌦 +11⁰C
Hamburg: 🌦 +8⁰C
Berlin: 🌦 +8⁰C

Or process them all at once:

$ curl -s 'localhost:8002/{Nuremberg,Hamburg,Berlin}?format=3'

To specify your own custom output format, use the special %-notation:

    c    Weather condition emoji
    C    Weather condition textual name
    h    Humidity
    t    Temperature (Actual)
    f    Temperature (Feels Like)
    w    Wind
    l    Location
    m    Moon phase 🌑🌒🌓🌔🌕🌖🌗🌘
    M    Moon day
    p    Precipitation (mm/3 hours)
    P    Pressure (hPa)

    D    Dawn
    S    Sunrise
    z    Zenith
    s    Sunset
    d    Dusk

Example:

$ curl localhost:8002/London?format="%l:+%c+%t"
London: ⛅️ +7⁰C

Data-rich output format (v2)

Note: Not yet fully implemented - see MISSING_FEATURES.md

In the data-rich output format (view code v2), additional weather and astronomical information is available:

$ curl localhost:8002/München?format=v2

JSON output

To fetch information in JSON format:

Note: Not yet fully implemented - see MISSING_FEATURES.md

$ curl localhost:8002/Detroit?format=j1

The result will look like:

{
  "current_condition": [{
    "FeelsLikeC": "25",
    "FeelsLikeF": "76",
    "cloudcover": "100",
    "humidity": "76",
    "temp_C": "22",
    "temp_F": "72",
    "weatherCode": "122",
    "weatherDesc": [{"value": "Overcast"}],
    "windspeedKmph": "7"
  }],
  ...
}

Prometheus Metrics Output

To fetch information in Prometheus format:

$ curl localhost:8002/Detroit?format=p1

A possible Prometheus configuration:

- job_name: 'wttr_in_detroit'
  static_configs:
    - targets: ['localhost:8002']
  metrics_path: '/Detroit'
  params:
    format: ['p1']

Building

# Debug build
zig build

# Release build
zig build -Doptimize=ReleaseSafe

# Run tests
zig build test

# Run
./zig-out/bin/wttr

Configuration

All configuration is via environment variables:

Variable Default Description
WTTR_LISTEN_HOST 0.0.0.0 Listen address
WTTR_LISTEN_PORT 8002 Listen port
WTTR_CACHE_DIR ~/.cache/wttr Cache directory
WTTR_CACHE_SIZE 10000 Max cached responses
WTTR_GEOLITE_PATH ~/.cache/wttr/GeoLite2-City.mmdb GeoIP database path
WTTR_GEOCACHE_FILE ~/.cache/wttr/geocache.json Location name cache
IP2LOCATION_API_KEY (none) Optional IP geolocation fallback
IP2LOCATION_CACHE_FILE ~/.cache/wttr/ip2location.cache IP2Location cache file
METNO_TOS_IDENTIFYING_EMAIL (none) Email for Met.no API identification
WTTR_ADMIN_PREFIX (none) Enables admin routes, e.g. /_admin
WTTR_PROXY_HOPS 1 Reverse proxies in front; 0 for none

Client address

The client address drives rate limiting and IP geolocation. Each reverse proxy appends the address it saw to X-Forwarded-For, so the client is taken to be the entry WTTR_PROXY_HOPS from the right; anything further left was written by the client and is ignored. X-Real-IP is used only when X-Forwarded-For is absent.

The server cannot tell whether a request actually came through the proxies. With the default of 1, the listener must be reachable only through one proxy, or any client can forge its address. Set the count to match the chain (e.g. 2 for CDN -> nginx -> wttr), or 0 if clients connect directly.

Admin routes

The operator commands (wttr pin, unpin, pins, explain) are also available over HTTP, plus a status report, but only when WTTR_ADMIN_PREFIX is set. When it is unset, none of these routes exist.

The server does not authenticate these routes. Whatever sits in front of it (reverse proxy, forward-auth, network policy) must restrict the prefix.

Method Route Equivalent
GET {prefix} list of routes
GET {prefix}/status versions, file ages, cache size, last 5 IP resolutions
GET {prefix}/pins wttr pins
PUT {prefix}/pins?cidr=<cidr>&location=<place> wttr pin <cidr> <place>
DELETE {prefix}/pins?cidr=<cidr> wttr unpin <cidr>
GET {prefix}/explain/<address>[?online=1] wttr explain <address> [--online]

Pin changes made over HTTP take effect immediately, with no SIGHUP. Changes use PUT and DELETE so a browser carrying an auth cookie cannot be tricked into making one from another site. The first path segment of the prefix stops working as a location, so pick one no place is named after: /_admin rather than /admin.

curl -X PUT 'https://wttr.example/_admin/pins?cidr=12.94.132.0/24&location=San+Francisco'
curl https://wttr.example/_admin/status

External Services

Required

  • Met.no Weather API - Weather data provider (free, no registration)
    • Set METNO_TOS_IDENTIFYING_EMAIL to identify yourself to Met.No
  • IP2Location.io - IP geolocation service
    • Sign up at https://www.ip2location.io/
    • Free tier: 30,000 requests/month
    • Set IP2LOCATION_API_KEY environment variable for higher limits

Auto-Downloaded

  • MaxMind GeoLite2 City - IP geolocation database
    • Downloaded automatically if missing
    • Stored in ~/.cache/wttr/GeoLite2-City.mmdb

Docker

Prebuilt images are available from https://git.lerch.org/lobo/-/packages/container/wttr/latest and can be pulled with docker pull git.lerch.org/lobo/wttr:latest or docker pull git.lerch.org/lobo/wttr:<shortsha> for a specific revision

# Build image. Note the binary must be in the directory
docker build -t wttr -f docker/Dockerfile .

# Run container
docker run -p 8002:8002 wttr

Documentation

License

Apache v2, matching wttr.in project from which this is derived. See LICENSE