- OpenWeatherのAPIをGo言語で使用するためのパッケージ
5日分の天気情報を3時間ごとに取得できます。
- 都市名 string型
- 日付 []string型
- 天気 []string型
- アイコン []string型
- 気温 []int型
- Go 1.10 or later
go get github.com/yuki9431/weather
import (
"fmt"
"github.com/yuki9431/weather"
)
func main() {
w, err := weather.New("<cityid>", "<appid>")
if err != nil {
fmt.Println(err)
}
for i, date := range w.GetDates() {
fmt.Println(date.String() + " : " + w.GetDescriptions()[i])
}
}
はじめにOpenWeatherのアカウントを作成し
API key(APPID)を取得する必要があります。
- New(cityId, appid)でweatherInfos型を取得する
- 下記メソッドで必要な情報を取得
OpenWeatherから5日間の天気情報を取得します。
天気情報はweatherInfos型で取得できます。
New()で取得した天気情報に含まれる都市名を取得します。
(TODO 現在は東京で固定しているが、可変にしたい)
New()で取得した天気情報に含まれる天気アイコンを表す文字列を取得します。
5日分*3時間毎の天気アイコンを[]string型で返します。
New()で取得した天気情報に含まれる日付を取得します。
5日分*3時間毎の日付を[]time.Time型で返します。
New()で取得した天気情報に含まれる天気(sun, rain等)を取得します。
5日分*3時間毎の天気を[]string型で返します。
New()で取得した天気情報に含まれる気温を取得します。
小数点以下はの値は四捨五入します。
5日分*3時間毎の気温を[]int型で返します。
天気アイコンを絵文字変換します。
(01d ⇒ ☀️)
日付を指定し、1日分の天気情報を取得できます。
- Fork (https://github.com/yuki9431/weather)
- Create a feature branch
- Commit your changes
- Rebase your local changes against the master branch
- Create new Pull Request