8000 Version 1 - rewrite by briandowns · Pull Request #90 · briandowns/openweathermap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Version 1 - rewrite #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go
go:
- 1.5.4
- 1.6.2
- 1.15.8
- 1.16.2
env:
- GOARCH: amd64
- GOARCH: 386
Expand Down
16 changes: 2 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
GOCMD = go
GOBUILD = $(GOCMD) build
GOGET = $(GOCMD) get -v
GOCLEAN = $(GOCMD) clean
GOINSTALL = $(GOCMD) install
GOTEST = $(GOCMD) test
GO = go

.PHONY: all

all: test

.PHONY: test
test:
$(GOTEST) -v -covermode=count -coverprofile=coverage.out ./...
$(GO) test -v -covermode=count -coverprofile=coverage.out ./...

.PHONY: build
build: test
$(GOBUILD)

.PHONY: install
install: test
$(GOINSTALL)
221 changes: 75 additions & 146 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![GoDoc](https://godoc.org/github.com/briandowns/openweathermap?status.svg)](https://godoc.org/github.com/briandowns/openweathermap) [![Build Status](https://travis-ci.org/briandowns/openweathermap.svg?branch=master)](https://travis-ci.org/briandowns/openweathermap) [![Coverage Status](https://coveralls.io/repos/github/briandowns/openweathermap/badge.svg?branch=master)](https://coveralls.io/github/briandowns/openweathermap?branch=master)

Go (golang) package for use with openweathermap.org's API.
Go (golang) package for use with openweathermap.org's HTTP API.

For more detail about the library and its features, reference your local godoc once installed.

Expand Down Expand Up @@ -71,7 +71,25 @@ Gain access to OpenWeatherMap icons and condition codes.

## 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
- 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

Expand All @@ -81,7 +99,7 @@ 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.
Full, simple example.

```Go
package main
Expand All @@ -91,189 +109,100 @@ import (
"fmt"
"os"

// Shortening the import reference name seems to make it a bit easier
owm "github.com/briandowns/openweathermap"
"github.com/briandowns/openweathermap"
)

var apiKey = os.Getenv("OWM_API_KEY")

func main() {
w, err := owm.NewCurrent("F", "ru", apiKey) // fahrenheit (imperial) with Russian output
opts := openweathermap.Opts{
Lang: "EN",
Unit: "F",
Client: &http.Client{
Timeout: time.Second * 5,
},
}
owm, err := openweathermap.New(&opts)
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", apiKey) // (internal - OpenWeatherMap reference for kelvin) with English output
if err != nil {
log.Fatalln(err)
}

w.CurrentByName("Phoenix,AZ")
fmt.Println(w)
cbn, err := owm.CurrentByName("Philadelphia")
if err != nil {
log.Fatalln(err)
}
fmt.Printf("%#v\n", cbn)
}
```

### Forecast Conditions in imperial (fahrenheit) by coordinates

```Go
func main() {
w, err := owm.NewForecast("5", "F", "FI", apiKey) // valid options for first parameter are "5" and "16"
if err != nil {
log.Fatalln(err)
}

w.DailyByCoordinates(
&owm.Coordinates{
Longitude: -112.07,
Latitude: 33.45,
},
5 // five days forecast
)
fmt.Println(w)
fdfbc, err := owm.FiveDayForecastByCoordinates(&openweathermap.Coordinates{Longitude: -75.1638, Latitude: 39.9523}, 10)
if err != nil {
log.Fatalln(err)
}
fmt.Printf("%#v\n", fdfbc)
```

### Current conditions in metric (celsius) by location ID

```Go
func main() {
w, err := owm.NewCurrent("C", "PL", apiKey)
if err != nil {
log.Fatalln(err)
}

w.CurrentByID(2172797)
fmt.Println(w)
owm.Unit = "C"
cbi, err := owm.CurrentByID(4560349)
if err != nil {
log.Fatalln(err)
}
fmt.Printf("%#v\n", cbi)
```

### Current conditions by zip code. 2 character country code required

```Go
func main() {
w, err := owm.NewCurrent("F", "EN", apiKey)
if err != nil {
log.Fatalln(err)
}

w.CurrentByZip(19125, "US")
fmt.Println(w)
cbz, err := owm.CurrentByZip("19127", "")
if err != nil {
log.Fatalln(err)
}
fmt.Printf("%#v\n", cbz)
```

### Configure http client
### History by Name

```Go
func main() {
client := &http.Client{}
w, err := owm.NewCurrent("F", "EN", apiKey, owm.WithHttpClient(client))
if err != nil {
log.Fatalln(err)
}
hbn, err := owm.HistoryByName("Philadelphia", &openweathermap.HistoricalParameters{
Start: 1369728000,
End: 1369789200,
Cnt: 4,
})
if err != nil {
log.Fatalln(err)
}
fmt.Printf("%#v\n", hbn)
```

### Current UV conditions

```Go
func main() {
uv, err := owm.NewUV(apiKey)
if err != nil {
log.Fatalln(err)
}

coord := &owm.Coordinates{
Longitude: 53.343497,
Latitude: -6.288379,
}

if err := uv.Current(coord); err != nil {
log.Fatalln(err)
}

fmt.Println(coord)
}
```

### Historical UV conditions

```Go
func main() {
uv, err := owm.NewUV(apiKey)
if err != nil {
log.Fatalln(err)
}

coord := &owm.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 := owm.NewUV(apiKey)
if err != nil {
log.Fatalln(err)
}

coord := &owm.Coordinates{
Longitude: 53.343497,
Latitude: -6.288379,
}

if err := uv.Current(coord); err != nil {
log.Fatalln(err)
}

info, err := uv.UVInformation()
if err != nil {
log.Fatalln(err)
}

fmt.Println(info)
uv, err := owm.UVCurrent(&openweathermap.Coordinates{
Latitude: 39.9523,
Longitude: -75.1638,
})
if err != nil {
log.Fatalln(err)
}
fmt.Printf("%#v\n", uv)
```

### Pollution Information

```Go
func main() {
pollution, err := owm.NewPollution(apiKey)
if err != nil {
log.Fatalln(err)
}

params := &owm.PollutionParameters{
Location: owm.Coordinates{
Latitude: 0.0,
Longitude: 10.0,
},
Datetime: "current",
}

if err := pollution.PollutionByParams(params); err != nil {
log.Fatalln(err)
}
p, err := owm.PollutionByParams(&openweathermap.PollutionParameters{
Location: openweathermap.Coordinates{
Latitude: 39.9523,
Longitude: -75.1638,
},
Datetime: "2006-01-02T15:04:05-0700",
})
if err != nil {
log.Fatalln(err)
}
```
fmt.Printf("%#v\n", p)
```
Loading
0