Skip to content

Add pirateweather.net backend#231

Merged
kordianbruck merged 6 commits intomasterfrom
copilot/finish-pr-194-implementation
Apr 11, 2026
Merged

Add pirateweather.net backend#231
kordianbruck merged 6 commits intomasterfrom
copilot/finish-pr-194-implementation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 11, 2026

Implements the pirateweather.net weather backend (finishing PR #194), fixing several bugs in the original before merging.

Motivation and Context

Adds support for pirateweather.net as a weather data backend. The original PR had correctness bugs and unfinished code that prevented it from being merged.

Description

Bug fixes from original PR:

  • Unit conversions (all wrong in original): precipIntensity mm/h → m/h (÷1000), visibility km → m (×1000), windSpeed/windGust m/s → km/h (×3.6) — SI units from the API require all three conversions
  • toForecast refactor: replaced 7 copy-pasted if numdays > N blocks (each with a stray log.Println("1") debug statement) with a loop grouping hourly data by day boundary; also fixed month-boundary detection using year+month+day comparison instead of day-of-month only
  • Debug logging: json.MarshalIndent(body, ...) on a []byte emits base64, not JSON — replaced with string(body); API key redacted from logged URL
  • Error handling: panic()log.Fatal() to match other backends; added missing API key presence check
  • JSON parsing: flags.nearest-station and elevation changed from uint to int — the API returns -999 as a "not implemented" sentinel for nearest-station, and elevations can be negative (below sea level locations)

Code style:

  • All exported type names lowercased (PirateweatherConfigpirateweatherConfig, etc.) to match conventions in other backends

Documentation:

  • Added pirateweather to the backends list in the Features section of README.md
  • Added a new Pirateweather configuration section to README.md under Backends, with a link to sign up for a free API key and a sample .wegorc config

Steps for Testing

Obtain a free API key from pirateweather.net and run:

wego -backend pirateweather.net -pirateweather-api-key <KEY> -location "lat,lon"

Test with -pirateweather-debug flag to verify debug output doesn't expose the API key and correctly prints the JSON response body.

Screenshots

Copilot AI and others added 2 commits April 11, 2026 22:47
Agent-Logs-Url: https://github.com/schachmat/wego/sessions/2287fbf8-7d43-4320-8352-1670e35c0c1a

Co-authored-by: kordianbruck <298860+kordianbruck@users.noreply.github.com>
…cal vars

Agent-Logs-Url: https://github.com/schachmat/wego/sessions/2287fbf8-7d43-4320-8352-1670e35c0c1a

Co-authored-by: kordianbruck <298860+kordianbruck@users.noreply.github.com>
@kordianbruck
Copy link
Copy Markdown
Collaborator

@copilot add a section to the README.md for how to configure pirateweather. Ensure any other documentation is up to date.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 11, 2026

@copilot add a section to the README.md for how to configure pirateweather. Ensure any other documentation is up to date.

Done in f180c4a. Added pirateweather to the backends list in the Features section and added a new configuration block under the Backends section with signup link, example .wegorc config, and a note that location must be specified as lat,lon coordinates.

@kordianbruck
Copy link
Copy Markdown
Collaborator

@copilot resolve any lint issues and also investigate/resolve this parsing mistake: "2026/04/12 00:59:18 Failed to unmarshal pirateweather response: json: cannot unmarshal number -999 into Go struct field .flags.nearest-station of type uint"

…eweather API

Agent-Logs-Url: https://github.com/schachmat/wego/sessions/0de82b82-bbfb-4bc3-b9e9-ff4bf68dca4f

Co-authored-by: kordianbruck <298860+kordianbruck@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 11, 2026

@copilot resolve any lint issues and also investigate/resolve this parsing mistake: "2026/04/12 00:59:18 Failed to unmarshal pirateweather response: json: cannot unmarshal number -999 into Go struct f...

Fixed in 3d38283. The nearest-station field in the Flags struct was typed as uint, but the Pirateweather API returns -999 as a "not implemented" sentinel value. Changed it to int. Also changed Elevation from uint to int since heights above sea level can be negative (e.g. Death Valley). No lint issues found (go vet and go build both pass cleanly).

@kordianbruck kordianbruck merged commit b520ebe into master Apr 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants