go-meteologix - Go packages for accessing Meteologix/Kachelmann Wetter/WeatherUS data
This package is still WIP
This Go package provides simple bindings to the
Meteologix/Kachelmann-Wetter API.
It provides access to "Stations", "Current Weather" and "Forecast". An API key or
username/password pair is required to access the endpoints. An API key can be configured
in your account settings.
go-meteologix follows idiomatic Go style and best practice. It's only dependency is
the Go Standard Library.
For Geolocation lookups, the package makes use of the
OpenStreetMap Nominatim API. This requires no API key.
Usage
The library is fully documented using the execellent GoDoc functionality. Check out
the full reference on pkg.go.dev for
details.
Examples
GeoLocation lookup
This program uses the OSM Nominatim API to lookup the GeoLocation data for Berlin, Germany.
On success it will return the Latitude
and Longitude
fields.
package main
import (
"fmt"
"os"
"github.com/wneessen/go-meteologix"
)
func main() {
c := meteologix.New()
gl, err := c.GetGeoLocationByName("Berlin, Germany")
if err != nil {
fmt.Println("GeoLocation lookup failed", err)
os.Exit(1)
}
fmt.Printf("GeoLocation - Latitude: %f, Longitude: %f\n", gl.Latitude,
gl.Longitude)
}
Lookup stations at a specific geolocation
This program makes use of the GeoLocation support in the package. It looks up the GeoLocation
of the location in question and queries the Kachelmann API for the station nearest to that
location. The returned list of stations is sorted by distance to the provided GeoLocation. In
our example we will return the first station in that list.
package main
import (
"fmt"
"os"
"github.com/wneessen/go-meteologix"
)
func main() {
c := meteologix.New(meteologix.WithAPIKey(os.Getenv("API_KEY")))
sl, err := c.StationSearchByLocation("Berlin, Germany")
if err != nil {
fmt.Printf("station lookup failed: %s", err)
os.Exit(1)
}
if len(sl) > 0 {
fmt.Printf("Station no. 1: %+v", sl[0])
}
}
Get latest station observation by station ID
This program takes a station ID and looks up the latest station observation data and returns
the Observation type. This type then has lots of methods to access the observation data. In
our example we will print out the formatted values for the current temperature and the dewpoint.
package main
import (
"fmt"
"math"
"os"
"github.com/wneessen/go-meteologix"
)
func main() {
c := meteologix.New(meteologix.WithAPIKey(os.Getenv("API_KEY")))
o, err := c.ObservationLatestByStationID("H744")
if err != nil {
fmt.Printf("station lookup failed: %s", err)
os.Exit(1)
}
fmt.Printf("Temperature at station: %s\n", o.Temperature())
if !math.IsNaN(o.Temperature().Value()) {
fmt.Printf("Temperature at station in F: %s\n", o.Temperature().FahrenheitString())
}
if o.Dewpoint().IsAvailable() {
fmt.Printf("Dewpoint in Fahrenheit: %s\n", o.Dewpoint().FahrenheitString())
}
}
Get latest station observation by location
This program takes a location string, searches for the weather station with the shortest distancen and looks up
the station's latest observation data. We then print out the temperature in C and F, as well as the station name
and the time of the measurement (if the data point is available from that station).
package main
import (
"fmt"
"os"
"github.com/wneessen/go-meteologix"
)
func main() {
c := meteologix.New(meteologix.WithAPIKey(os.Getenv("API_KEY")))
o, s, err := c.ObservationLatestByLocation("Ehrenfeld, Germany")
if err != nil {
fmt.Printf("Failed: %s\n", err)
os.Exit(1)
}
if o.Temperature().IsAvailable() {
fmt.Printf("Temperature at %s: %s/%s (time of measurement: %s)\n",
s.Name, o.Temperature(), o.Temperature().FahrenheitString(),
o.Temperature().DateTime().Local().Format("15:04h"))
}
}
Authors/Contributors
go-meteologix was authored and developed by Winni Neessen.
Big thanks to the following people, for contributing to the go-meteologix project
(either in form of code, reviewing code, writing documenation or contributing in any other form):