mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Output from 'dep status': PROJECT CONSTRAINT VERSION REVISION LATEST PKGS USED cloud.google.com/go v0.23.0 v0.23.0 0fd7230 v0.23.0 1 github.com/briandowns/openweathermap ^0.11.0 0.11 1b87579 0.11 1 github.com/gdamore/encoding branch master branch master b23993c b23993c 1 github.com/gdamore/tcell ^1.0.0 v1.0.0 061d51a v1.0.0 2 github.com/go-test/deep ^1.0.1 v1.0.1 6592d9c v1.0.1 1 github.com/golang/protobuf v1.1.0 v1.1.0 b4deda0 v1.1.0 1 github.com/google/go-github branch master branch master 2ae5df7 2ae5df7 1 github.com/google/go-querystring branch master branch master 53e6ce1 53e6ce1 1 github.com/jessevdk/go-flags ^1.4.0 v1.4.0 c6ca198 v1.4.0 1 github.com/lucasb-eyer/go-colorful v1.0 v1.0 345fbb3 v1.0 1 github.com/mattn/go-runewidth v0.0.2 v0.0.2 9e777a8 v0.0.2 1 github.com/olebedev/config branch master branch master 9a10d05 9a10d05 1 github.com/radovskyb/watcher ^1.0.2 v1.0.2 6145e14 v1.0.2 1 github.com/rivo/tview branch master branch master 71ecf1f 71ecf1f 1 github.com/yfronto/newrelic branch master branch master f7fa0c6 f7fa0c6 1 golang.org/x/net branch master branch master 1e49130 1e49130 2 golang.org/x/oauth2 branch master branch master 1e0a3fa 1e0a3fa 5 golang.org/x/text v0.3.0 v0.3.0 f21a4df v0.3.0 5 google.golang.org/api branch master branch master 00e3bb8 00e3bb8 4 google.golang.org/appengine v1.0.0 v1.0.0 150dc57 v1.0.0 10 gopkg.in/yaml.v2 ^2.2.1 v2.2.1 5420a8b v2.2.1 1 See https://golang.github.io/dep/docs/daily-dep.html
266 lines
5.4 KiB
Markdown
266 lines
5.4 KiB
Markdown
# OpenWeatherMap Go API
|
|
|
|
[](https://godoc.org/github.com/briandowns/openweathermap) [](https://travis-ci.org/briandowns/openweathermap) [](https://coveralls.io/github/briandowns/openweathermap?branch=master)
|
|
|
|
Go (golang) package for use with openweathermap.org's API.
|
|
|
|
For more detail about the library and its features, reference your local godoc once installed.
|
|
|
|
[Website](https://briandowns.github.io/openweathermap)!
|
|
|
|
To use the OpenweatherMap API, you need to obtain an API key. Sign up [here](http://home.openweathermap.org/users/sign_up). Once you have your key, create an environment variable called `OWM_API_KEY`. Start coding!
|
|
|
|
[Slack Channel](https://openweathermapgolang.slack.com/messages/general)
|
|
|
|
Contributions welcome!
|
|
|
|
## Features
|
|
|
|
### Current Weather Conditions
|
|
|
|
- By City
|
|
- By City,St (State)
|
|
- By City,Co (Country)
|
|
- By City ID
|
|
- By Zip,Co (Country)
|
|
- By Longitude and Latitude
|
|
|
|
## Forecast
|
|
|
|
Get the weather conditions for a given number of days.
|
|
|
|
- By City
|
|
- By City,St (State)
|
|
- By City,Co (Country)
|
|
- By City ID
|
|
- By Longitude and Latitude
|
|
|
|
### Access to Condition Codes and Icons
|
|
|
|
Gain access to OpenWeatherMap icons and condition codes.
|
|
|
|
- Thunderstorms
|
|
- Drizzle
|
|
- Rain
|
|
- Snow
|
|
- Atmosphere
|
|
- Clouds
|
|
- Extreme
|
|
- Additional
|
|
|
|
### Data Available in Multiple Measurement Systems
|
|
|
|
- Fahrenheit (OpenWeatherMap API - imperial)
|
|
- Celsius (OpenWeatherMap API - metric)
|
|
- Kelvin (OpenWeatherMap API - internal)
|
|
|
|
### UV Index Data
|
|
|
|
- Current
|
|
- Historical
|
|
|
|
### Pollution Data
|
|
|
|
- Current
|
|
|
|
## Historical Conditions
|
|
|
|
- By Name
|
|
- By ID
|
|
- By Coordinates
|
|
|
|
## Supported Languages
|
|
|
|
English - en, Russian - ru, Italian - it, Spanish - es (or sp), Ukrainian - uk (or ua), German - de, Portuguese - pt, Romanian - ro, Polish - pl, Finnish - fi, Dutch - nl, French - fr, Bulgarian - bg, Swedish - sv (or se), Chinese Traditional - zh_tw, Chinese Simplified - zh (or zh_cn), Turkish - tr, Croatian - hr, Catalan - ca
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
go get github.com/briandowns/openweathermap
|
|
```
|
|
|
|
## Examples
|
|
|
|
There are a few full examples in the examples directory that can be referenced. 1 is a command line application and 1 is a simple web application.
|
|
|
|
```Go
|
|
package main
|
|
|
|
import (
|
|
"log"
|
|
"fmt"
|
|
|
|
// Shortening the import reference name seems to make it a bit easier
|
|
owm "github.com/briandowns/openweathermap"
|
|
)
|
|
|
|
func main() {
|
|
w, err := owm.NewCurrent("F", "ru") // fahrenheit (imperial) with Russian output
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
w.CurrentByName("Phoenix")
|
|
fmt.Println(w)
|
|
}
|
|
```
|
|
|
|
### Current Conditions by location name
|
|
|
|
```Go
|
|
func main() {
|
|
w, err := owm.NewCurrent("K", "EN") // (internal - OpenWeatherMap reference for kelvin) with English output
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
w.CurrentByName("Phoenix,AZ")
|
|
fmt.Println(w)
|
|
}
|
|
```
|
|
|
|
### Forecast Conditions in imperial (fahrenheit) by coordinates
|
|
|
|
```Go
|
|
func main() {
|
|
w, err := owm.NewForecast("F", "FI")
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
w.DailyByCoordinates(
|
|
&Coordinates{
|
|
Longitude: -112.07,
|
|
Latitude: 33.45,
|
|
},
|
|
)
|
|
fmt.Println(w)
|
|
}
|
|
```
|
|
|
|
### Current conditions in metric (celsius) by location ID
|
|
|
|
```Go
|
|
func main() {
|
|
w, err := owm.NewCurrent("C", "PL")
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
w.CurrentByID(2172797)
|
|
fmt.Println(w)
|
|
}
|
|
```
|
|
|
|
### Current conditions by zip code. 2 character country code required
|
|
|
|
```Go
|
|
func main() {
|
|
w, err := owm.NewCurrent("F", "EN")
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
w.CurrentByZip(19125, "US")
|
|
fmt.Println(w)
|
|
}
|
|
```
|
|
|
|
### Configure http client
|
|
|
|
```Go
|
|
func main() {
|
|
client := &http.Client{}
|
|
w, err := owm.NewCurrent("F", "EN", owm.WithHttpClient(client))
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
}
|
|
```
|
|
|
|
### Current UV conditions
|
|
|
|
```Go
|
|
func main() {
|
|
uv, err := NewUV()
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
coord := &Coordinates{
|
|
Longitude: 53.343497,
|
|
Latitude: -6.288379,
|
|
}
|
|
|
|
if err := uv.Current(coord); err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
```
|
|
|
|
### Historical UV conditions
|
|
|
|
```Go
|
|
func main() {
|
|
uv, err := NewUV()
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
coord := &Coordinates{
|
|
Longitude: 54.995656,
|
|
Latitude: -7.326834,
|
|
}
|
|
|
|
end := time.Now().UTC()
|
|
start := time.Now().UTC().Add(-time.Hour * time.Duration(24))
|
|
|
|
if err := uv.Historical(coord, start, end); err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
}
|
|
```
|
|
|
|
### UV Information
|
|
|
|
```Go
|
|
func main() {
|
|
uv, err := NewUV()
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
if err := uv.Current(coords); err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
info, err := uv.UVInformation()
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
}
|
|
```
|
|
|
|
### Pollution Information
|
|
|
|
```Go
|
|
func main() {
|
|
pollution, err := NewPollution()
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
params := &PollutionParameters{
|
|
Location: Coordinates{
|
|
Latitude: 0.0,
|
|
Longitude: 10.0,
|
|
},
|
|
Datetime: "current",
|
|
}
|
|
|
|
if err := pollution.PollutionByParams(params); err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
}
|
|
```
|