mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Vendor dependencies using golang/dep
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
This commit is contained in:
committed by
Chris Cummer
parent
5c4f5ce638
commit
227720e0d1
31
vendor/github.com/briandowns/openweathermap/.gitignore
generated
vendored
Normal file
31
vendor/github.com/briandowns/openweathermap/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
# Created by .gitignore support plugin (hsz.mobi)
|
||||
### Go template
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
|
||||
.idea
|
||||
*.iml
|
||||
|
||||
coverage.*
|
||||
29
vendor/github.com/briandowns/openweathermap/.travis.yml
generated
vendored
Normal file
29
vendor/github.com/briandowns/openweathermap/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
language: go
|
||||
go:
|
||||
- 1.5.4
|
||||
- 1.6.2
|
||||
env:
|
||||
- GOARCH: amd64
|
||||
- GOARCH: 386
|
||||
addons:
|
||||
hosts:
|
||||
- api.openweathermap.org
|
||||
before_install:
|
||||
- sudo apt-get -qq update
|
||||
- sudo apt-get install -y socat
|
||||
- cat /etc/hosts
|
||||
- wget http://ipinfo.io/ip -qO -
|
||||
- sudo socat TCP-LISTEN:80,fork TCP:${RTCP_HOST}:${RTCP_PORT} > /tmp/socat.log 2>&1 &
|
||||
- go get github.com/mattn/goveralls
|
||||
- go get golang.org/x/tools/cmd/cover
|
||||
script:
|
||||
- make test
|
||||
- $HOME/gopath/bin/goveralls -service=travis-ci -repotoken $COVERALLS_TOKEN
|
||||
notifications:
|
||||
email:
|
||||
recipients:
|
||||
- brian.downs@gmail.com
|
||||
on_success: change
|
||||
on_failure: always
|
||||
after_success:
|
||||
- coveralls
|
||||
14
vendor/github.com/briandowns/openweathermap/CONTRIBUTING.md
generated
vendored
Normal file
14
vendor/github.com/briandowns/openweathermap/CONTRIBUTING.md
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
# Contributing to openweathermap
|
||||
|
||||
## Issues
|
||||
|
||||
### Reporting an Issue
|
||||
|
||||
* Please add an issue [here](https://github.com/briandowns/openweathermap/issues) and utilize the appropriate label.
|
||||
|
||||
## Fixing Problems and/or Adding Features
|
||||
|
||||
* Feel free to fork and fix an issue(s) or add a feature.
|
||||
* Please provide tests for the submitted code.
|
||||
* Run `go fmt` and `go vet`
|
||||
* Once the pull request is submitted, it'll be tested and merged.
|
||||
174
vendor/github.com/briandowns/openweathermap/LICENSE
generated
vendored
Normal file
174
vendor/github.com/briandowns/openweathermap/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,174 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
19
vendor/github.com/briandowns/openweathermap/Makefile
generated
vendored
Normal file
19
vendor/github.com/briandowns/openweathermap/Makefile
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
GOCMD = go
|
||||
GOBUILD = $(GOCMD) build
|
||||
GOGET = $(GOCMD) get -v
|
||||
GOCLEAN = $(GOCMD) clean
|
||||
GOINSTALL = $(GOCMD) install
|
||||
GOTEST = $(GOCMD) test
|
||||
|
||||
.PHONY: all
|
||||
|
||||
all: test
|
||||
|
||||
test:
|
||||
$(GOTEST) -v -covermode=count -coverprofile=coverage.out ./...
|
||||
|
||||
build: test
|
||||
$(GOBUILD)
|
||||
|
||||
install: test
|
||||
$(GOINSTALL)
|
||||
265
vendor/github.com/briandowns/openweathermap/README.md
generated
vendored
Normal file
265
vendor/github.com/briandowns/openweathermap/README.md
generated
vendored
Normal file
@@ -0,0 +1,265 @@
|
||||
# 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)
|
||||
}
|
||||
}
|
||||
```
|
||||
185
vendor/github.com/briandowns/openweathermap/conditions.go
generated
vendored
Normal file
185
vendor/github.com/briandowns/openweathermap/conditions.go
generated
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
// Copyright 2015 Brian J. Downs
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package openweathermap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
// IconData holds the relevant info for linking icons to conditions.
|
||||
type IconData struct {
|
||||
Condition string
|
||||
Day string
|
||||
Night string
|
||||
}
|
||||
|
||||
// ConditionData holds data structure for weather conditions information.
|
||||
type ConditionData struct {
|
||||
ID int
|
||||
Meaning string
|
||||
Icon1 string
|
||||
Icon2 string
|
||||
}
|
||||
|
||||
// RetrieveIcon will get the specified icon from the API.
|
||||
func RetrieveIcon(destination, iconFile string) (int64, error) {
|
||||
fullFilePath := fmt.Sprintf("%s/%s", destination, iconFile)
|
||||
|
||||
// Check to see if we've already gotten that icon file. If so, use it
|
||||
// rather than getting it again.
|
||||
if _, err := os.Stat(fullFilePath); err != nil {
|
||||
response, err := http.Get(fmt.Sprintf(iconURL, iconFile))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
// Create the icon file
|
||||
out, err := os.Create(fullFilePath)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
// Fill the empty file with the actual content
|
||||
n, err := io.Copy(out, response.Body)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// IconList is a slice of IconData pointers
|
||||
var IconList = []*IconData{
|
||||
{Condition: "clear sky", Day: "01d.png", Night: "01n.png"},
|
||||
{Condition: "few clouds", Day: "02d.png", Night: "02n.png"},
|
||||
{Condition: "scattered clouds", Day: "03d.png", Night: "03n.png"},
|
||||
{Condition: "broken clouds", Day: "04d.png", Night: "04n.png"},
|
||||
{Condition: "shower rain", Day: "09d.png", Night: "09n.png"},
|
||||
{Condition: "rain", Day: "10d.png", Night: "10n.png"},
|
||||
{Condition: "thunderstorm", Day: "11d.png", Night: "11n.png"},
|
||||
{Condition: "snow", Day: "13d.png", Night: "13n.png"},
|
||||
{Condition: "mist", Day: "50d.png", Night: "50n.png"},
|
||||
}
|
||||
|
||||
// ThunderstormConditions is a slice of ConditionData pointers
|
||||
var ThunderstormConditions = []*ConditionData{
|
||||
{ID: 200, Meaning: "thunderstorm with light rain", Icon1: "11d.png"},
|
||||
{ID: 201, Meaning: "thunderstorm with rain", Icon1: "11d.png"},
|
||||
{ID: 202, Meaning: "thunderstorm with heavy rain", Icon1: "11d.png"},
|
||||
{ID: 210, Meaning: "light thunderstorm", Icon1: "11d.png"},
|
||||
{ID: 211, Meaning: "thunderstorm", Icon1: "11d.png"},
|
||||
{ID: 212, Meaning: "heavy thunderstorm", Icon1: "11d.png"},
|
||||
{ID: 221, Meaning: "ragged thunderstorm", Icon1: "11d.png"},
|
||||
{ID: 230, Meaning: "thunderstorm with light drizzle", Icon1: "11d.png"},
|
||||
{ID: 231, Meaning: "thunderstorm with drizzle", Icon1: "11d.png"},
|
||||
{ID: 232, Meaning: "thunderstorm with heavy drizzle", Icon1: "11d.png"},
|
||||
}
|
||||
|
||||
// DrizzleConditions is a slice of ConditionData pointers
|
||||
var DrizzleConditions = []*ConditionData{
|
||||
{ID: 300, Meaning: "light intensity drizzle", Icon1: "09d.png"},
|
||||
{ID: 301, Meaning: "drizzle", Icon1: "09d.png"},
|
||||
{ID: 302, Meaning: "heavy intensity drizzle", Icon1: "09d.png"},
|
||||
{ID: 310, Meaning: "light intensity drizzle rain", Icon1: "09d.png"},
|
||||
{ID: 311, Meaning: "drizzle rain", Icon1: "09d.png"},
|
||||
{ID: 312, Meaning: "heavy intensity drizzle rain", Icon1: "09d.png"},
|
||||
{ID: 313, Meaning: "shower rain and drizzle", Icon1: "09d.png"},
|
||||
{ID: 314, Meaning: "heavy shower rain and drizzle", Icon1: "09d.png"},
|
||||
{ID: 321, Meaning: "shower drizzle", Icon1: "09d.png"},
|
||||
}
|
||||
|
||||
// RainConditions is a slice of ConditionData pointers
|
||||
var RainConditions = []*ConditionData{
|
||||
{ID: 500, Meaning: "light rain", Icon1: "09d.png"},
|
||||
{ID: 501, Meaning: "moderate rain", Icon1: "09d.png"},
|
||||
{ID: 502, Meaning: "heavy intensity rain", Icon1: "09d.png"},
|
||||
{ID: 503, Meaning: "very heavy rain", Icon1: "09d.png"},
|
||||
{ID: 504, Meaning: "extreme rain", Icon1: "09d.png"},
|
||||
{ID: 511, Meaning: "freezing rain", Icon1: "13d.png"},
|
||||
{ID: 520, Meaning: "light intensity shower rain", Icon1: "09d.png"},
|
||||
{ID: 521, Meaning: "shower rain", Icon1: "09d.png"},
|
||||
{ID: 522, Meaning: "heavy intensity shower rain", Icon1: "09d.png"},
|
||||
{ID: 531, Meaning: "ragged shower rain", Icon1: "09d.png"},
|
||||
}
|
||||
|
||||
// SnowConditions is a slice of ConditionData pointers
|
||||
var SnowConditions = []*ConditionData{
|
||||
{ID: 600, Meaning: "light snow", Icon1: "13d.png"},
|
||||
{ID: 601, Meaning: "snow", Icon1: "13d.png"},
|
||||
{ID: 602, Meaning: "heavy snow", Icon1: "13d.png"},
|
||||
{ID: 611, Meaning: "sleet", Icon1: "13d.png"},
|
||||
{ID: 612, Meaning: "shower sleet", Icon1: "13d.png"},
|
||||
{ID: 615, Meaning: "light rain and snow", Icon1: "13d.png"},
|
||||
{ID: 616, Meaning: "rain and snow", Icon1: "13d.png"},
|
||||
{ID: 620, Meaning: "light shower snow", Icon1: "13d.png"},
|
||||
{ID: 621, Meaning: "shower snow", Icon1: "13d.png"},
|
||||
{ID: 622, Meaning: "heavy shower snow", Icon1: "13d.png"},
|
||||
}
|
||||
|
||||
// AtmosphereConditions is a slice of ConditionData pointers
|
||||
var AtmosphereConditions = []*ConditionData{
|
||||
{ID: 701, Meaning: "mist", Icon1: "50d.png"},
|
||||
{ID: 711, Meaning: "smoke", Icon1: "50d.png"},
|
||||
{ID: 721, Meaning: "haze", Icon1: "50d.png"},
|
||||
{ID: 731, Meaning: "sand, dust whirls", Icon1: "50d.png"},
|
||||
{ID: 741, Meaning: "fog", Icon1: "50d.png"},
|
||||
{ID: 751, Meaning: "sand", Icon1: "50d.png"},
|
||||
{ID: 761, Meaning: "dust", Icon1: "50d.png"},
|
||||
{ID: 762, Meaning: "volcanic ash", Icon1: "50d.png"},
|
||||
{ID: 771, Meaning: "squalls", Icon1: "50d.png"},
|
||||
{ID: 781, Meaning: "tornado", Icon1: "50d.png"},
|
||||
}
|
||||
|
||||
// CloudConditions is a slice of ConditionData pointers
|
||||
var CloudConditions = []*ConditionData{
|
||||
{ID: 800, Meaning: "clear sky", Icon1: "01d.png", Icon2: "01n.png"},
|
||||
{ID: 801, Meaning: "few clouds", Icon1: "02d.png", Icon2: " 02n.png"},
|
||||
{ID: 802, Meaning: "scattered clouds", Icon1: "03d.png", Icon2: "03d.png"},
|
||||
{ID: 803, Meaning: "broken clouds", Icon1: "04d.png", Icon2: "03d.png"},
|
||||
{ID: 804, Meaning: "overcast clouds", Icon1: "04d.png", Icon2: "04d.png"},
|
||||
}
|
||||
|
||||
// ExtremeConditions is a slice of ConditionData pointers
|
||||
var ExtremeConditions = []*ConditionData{
|
||||
{ID: 900, Meaning: "tornado", Icon1: ""},
|
||||
{ID: 901, Meaning: "tropical storm", Icon1: ""},
|
||||
{ID: 902, Meaning: "hurricane", Icon1: ""},
|
||||
{ID: 903, Meaning: "cold", Icon1: ""},
|
||||
{ID: 904, Meaning: "hot", Icon1: ""},
|
||||
{ID: 905, Meaning: "windy", Icon1: ""},
|
||||
{ID: 906, Meaning: "hail", Icon1: ""},
|
||||
}
|
||||
|
||||
// AdditionalConditions is a slive of ConditionData pointers
|
||||
var AdditionalConditions = []*ConditionData{
|
||||
{ID: 951, Meaning: "calm", Icon1: ""},
|
||||
{ID: 952, Meaning: "light breeze", Icon1: ""},
|
||||
{ID: 953, Meaning: "gentle breeze", Icon1: ""},
|
||||
{ID: 954, Meaning: "moderate breeze", Icon1: ""},
|
||||
{ID: 955, Meaning: "fresh breeze", Icon1: ""},
|
||||
{ID: 956, Meaning: "strong breeze", Icon1: ""},
|
||||
{ID: 957, Meaning: "high wind, near gale", Icon1: ""},
|
||||
{ID: 958, Meaning: "gale", Icon1: ""},
|
||||
{ID: 959, Meaning: "severe gale", Icon1: ""},
|
||||
{ID: 960, Meaning: "storm", Icon1: ""},
|
||||
{ID: 961, Meaning: "violent storm", Icon1: ""},
|
||||
{ID: 962, Meaning: "hurricane", Icon1: ""},
|
||||
}
|
||||
143
vendor/github.com/briandowns/openweathermap/current.go
generated
vendored
Normal file
143
vendor/github.com/briandowns/openweathermap/current.go
generated
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
// Copyright 2015 Brian J. Downs
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package openweathermap
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CurrentWeatherData struct contains an aggregate view of the structs
|
||||
// defined above for JSON to be unmarshaled into.
|
||||
type CurrentWeatherData struct {
|
||||
GeoPos Coordinates `json:"coord"`
|
||||
Sys Sys `json:"sys"`
|
||||
Base string `json:"base"`
|
||||
Weather []Weather `json:"weather"`
|
||||
Main Main `json:"main"`
|
||||
Wind Wind `json:"wind"`
|
||||
Clouds Clouds `json:"clouds"`
|
||||
Rain Rain `json:"rain"`
|
||||
Snow Snow `json:"snow"`
|
||||
Dt int `json:"dt"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Cod int `json:"cod"`
|
||||
Unit string
|
||||
Lang string
|
||||
Key string
|
||||
*Settings
|
||||
}
|
||||
|
||||
// NewCurrent returns a new CurrentWeatherData pointer with the supplied parameters
|
||||
func NewCurrent(unit, lang, key string, options ...Option) (*CurrentWeatherData, error) {
|
||||
unitChoice := strings.ToUpper(unit)
|
||||
langChoice := strings.ToUpper(lang)
|
||||
|
||||
c := &CurrentWeatherData{
|
||||
Settings: NewSettings(),
|
||||
}
|
||||
|
||||
if ValidDataUnit(unitChoice) {
|
||||
c.Unit = DataUnits[unitChoice]
|
||||
} else {
|
||||
return nil, errUnitUnavailable
|
||||
}
|
||||
|
||||
if ValidLangCode(langChoice) {
|
||||
c.Lang = langChoice
|
||||
} else {
|
||||
return nil, errLangUnavailable
|
||||
}
|
||||
var err error
|
||||
c.Key, err = setKey(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := setOptions(c.Settings, options); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// CurrentByName will provide the current weather with the provided
|
||||
// location name.
|
||||
func (w *CurrentWeatherData) CurrentByName(location string) error {
|
||||
response, err := w.client.Get(fmt.Sprintf(fmt.Sprintf(baseURL, "appid=%s&q=%s&units=%s&lang=%s"), w.Key, url.QueryEscape(location), w.Unit, w.Lang))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
if err := json.NewDecoder(response.Body).Decode(&w); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CurrentByCoordinates will provide the current weather with the
|
||||
// provided location coordinates.
|
||||
func (w *CurrentWeatherData) CurrentByCoordinates(location *Coordinates) error {
|
||||
response, err := w.client.Get(fmt.Sprintf(fmt.Sprintf(baseURL, "appid=%s&lat=%f&lon=%f&units=%s&lang=%s"), w.Key, location.Latitude, location.Longitude, w.Unit, w.Lang))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
if err = json.NewDecoder(response.Body).Decode(&w); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CurrentByID will provide the current weather with the
|
||||
// provided location ID.
|
||||
func (w *CurrentWeatherData) CurrentByID(id int) error {
|
||||
response, err := w.client.Get(fmt.Sprintf(fmt.Sprintf(baseURL, "appid=%s&id=%d&units=%s&lang=%s"), w.Key, id, w.Unit, w.Lang))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
if err = json.NewDecoder(response.Body).Decode(&w); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CurrentByZip will provide the current weather for the
|
||||
// provided zip code.
|
||||
func (w *CurrentWeatherData) CurrentByZip(zip int, countryCode string) error {
|
||||
response, err := w.client.Get(fmt.Sprintf(fmt.Sprintf(baseURL, "appid=%s&zip=%d,%s&units=%s&lang=%s"), w.Key, zip, countryCode, w.Unit, w.Lang))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
if err = json.NewDecoder(response.Body).Decode(&w); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CurrentByArea will provide the current weather for the
|
||||
// provided area.
|
||||
func (w *CurrentWeatherData) CurrentByArea() {}
|
||||
18
vendor/github.com/briandowns/openweathermap/doc.go
generated
vendored
Normal file
18
vendor/github.com/briandowns/openweathermap/doc.go
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright 2015 Brian J. Downs
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package openweathermap is a library for use to access the
|
||||
// http://openweathermap.org API. JSON is the only return format supported
|
||||
// at this time.
|
||||
package openweathermap
|
||||
151
vendor/github.com/briandowns/openweathermap/forecast.go
generated
vendored
Normal file
151
vendor/github.com/briandowns/openweathermap/forecast.go
generated
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
// Copyright 2015 Brian J. Downs
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package openweathermap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ForecastSys area population
|
||||
type ForecastSys struct {
|
||||
Population int `json:"population"`
|
||||
}
|
||||
|
||||
// Temperature holds returned termperate sure stats
|
||||
type Temperature struct {
|
||||
Day float64 `json:"day"`
|
||||
Min float64 `json:"min"`
|
||||
Max float64 `json:"max"`
|
||||
Night float64 `json:"night"`
|
||||
Eve float64 `json:"eve"`
|
||||
Morn float64 `json:"morn"`
|
||||
}
|
||||
|
||||
// City data for given location
|
||||
type City struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Coord Coordinates `json:"coord"`
|
||||
Country string `json:"country"`
|
||||
Population int `json:"population"`
|
||||
Sys ForecastSys `json:"sys"`
|
||||
}
|
||||
|
||||
type ForecastWeather interface {
|
||||
DailyByName(location string, days int) error
|
||||
DailyByCoordinates(location *Coordinates, days int) error
|
||||
DailyByID(id, days int) error
|
||||
}
|
||||
|
||||
// json served by OWM API can take different forms, so all of them must be matched
|
||||
// by corresponding data type and unmarshall method
|
||||
type ForecastWeatherJson interface {
|
||||
Decode(r io.Reader) error
|
||||
}
|
||||
|
||||
type ForecastWeatherData struct {
|
||||
Unit string
|
||||
Lang string
|
||||
Key string
|
||||
baseURL string
|
||||
*Settings
|
||||
ForecastWeatherJson
|
||||
}
|
||||
|
||||
// NewForecast returns a new HistoricalWeatherData pointer with
|
||||
// the supplied arguments.
|
||||
func NewForecast(forecastType, unit, lang, key string, options ...Option) (*ForecastWeatherData, error) {
|
||||
unitChoice := strings.ToUpper(unit)
|
||||
langChoice := strings.ToUpper(lang)
|
||||
|
||||
if forecastType != "16" && forecastType != "5" {
|
||||
return nil, errForecastUnavailable
|
||||
}
|
||||
|
||||
if !ValidDataUnit(unitChoice) {
|
||||
return nil, errUnitUnavailable
|
||||
}
|
||||
|
||||
if !ValidLangCode(langChoice) {
|
||||
return nil, errLangUnavailable
|
||||
}
|
||||
|
||||
settings := NewSettings()
|
||||
if err := setOptions(settings, options); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var err error
|
||||
k, err := setKey(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
forecastData := ForecastWeatherData{
|
||||
Unit: DataUnits[unitChoice],
|
||||
Lang: langChoice,
|
||||
Key: k,
|
||||
Settings: settings,
|
||||
}
|
||||
|
||||
if forecastType == "16" {
|
||||
forecastData.baseURL = forecast16Base
|
||||
forecastData.ForecastWeatherJson = &Forecast16WeatherData{}
|
||||
} else {
|
||||
forecastData.baseURL = forecast5Base
|
||||
forecastData.ForecastWeatherJson = &Forecast5WeatherData{}
|
||||
}
|
||||
|
||||
return &forecastData, nil
|
||||
}
|
||||
|
||||
// DailyByName will provide a forecast for the location given for the
|
||||
// number of days given.
|
||||
func (f *ForecastWeatherData) DailyByName(location string, days int) error {
|
||||
response, err := f.client.Get(fmt.Sprintf(f.baseURL, f.Key, fmt.Sprintf("%s=%s", "q", url.QueryEscape(location)), f.Unit, f.Lang, days))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
return f.ForecastWeatherJson.Decode(response.Body)
|
||||
}
|
||||
|
||||
// DailyByCoordinates will provide a forecast for the coordinates ID give
|
||||
// for the number of days given.
|
||||
func (f *ForecastWeatherData) DailyByCoordinates(location *Coordinates, days int) error {
|
||||
response, err := f.client.Get(fmt.Sprintf(f.baseURL, f.Key, fmt.Sprintf("lat=%f&lon=%f", location.Latitude, location.Longitude), f.Unit, f.Lang, days))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
return f.ForecastWeatherJson.Decode(response.Body)
|
||||
}
|
||||
|
||||
// DailyByID will provide a forecast for the location ID give for the
|
||||
// number of days given.
|
||||
func (f *ForecastWeatherData) DailyByID(id, days int) error {
|
||||
response, err := f.client.Get(fmt.Sprintf(f.baseURL, f.Key, fmt.Sprintf("%s=%s", "id", strconv.Itoa(id)), f.Unit, f.Lang, days))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
return f.ForecastWeatherJson.Decode(response.Body)
|
||||
}
|
||||
36
vendor/github.com/briandowns/openweathermap/forecast16.go
generated
vendored
Normal file
36
vendor/github.com/briandowns/openweathermap/forecast16.go
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
package openweathermap
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
// Forecast16WeatherList holds specific query data
|
||||
type Forecast16WeatherList struct {
|
||||
Dt int `json:"dt"`
|
||||
Temp Temperature `json:"temp"`
|
||||
Pressure float64 `json:"pressure"`
|
||||
Humidity int `json:"humidity"`
|
||||
Weather []Weather `json:"weather"`
|
||||
Speed float64 `json:"speed"`
|
||||
Deg int `json:"deg"`
|
||||
Clouds int `json:"clouds"`
|
||||
Snow float64 `json:"snow"`
|
||||
Rain float64 `json:"rain"`
|
||||
}
|
||||
|
||||
// Forecast16WeatherData will hold returned data from queries
|
||||
type Forecast16WeatherData struct {
|
||||
COD int `json:"cod"`
|
||||
Message string `json:"message"`
|
||||
City City `json:"city"`
|
||||
Cnt int `json:"cnt"`
|
||||
List []Forecast16WeatherList `json:"list"`
|
||||
}
|
||||
|
||||
func (f *Forecast16WeatherData) Decode(r io.Reader) error {
|
||||
if err := json.NewDecoder(r).Decode(&f); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
50
vendor/github.com/briandowns/openweathermap/forecast5.go
generated
vendored
Normal file
50
vendor/github.com/briandowns/openweathermap/forecast5.go
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
package openweathermap
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type DtTxt struct {
|
||||
time.Time
|
||||
}
|
||||
|
||||
func (dt *DtTxt) UnmarshalJSON(b []byte) error {
|
||||
t, err := time.Parse("2006-01-02 15:04:05", strings.Trim(string(b), "\""))
|
||||
dt.Time = t
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *DtTxt) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(t)
|
||||
}
|
||||
|
||||
// Forecast5WeatherList holds specific query data
|
||||
type Forecast5WeatherList struct {
|
||||
Dt int `json:"dt"`
|
||||
Main Main `json:"main"`
|
||||
Weather []Weather `json:"weather"`
|
||||
Clouds Clouds `json:"clouds"`
|
||||
Wind Wind `json:"wind"`
|
||||
Rain Rain `json:"rain"`
|
||||
Snow Snow `json:"snow"`
|
||||
DtTxt DtTxt `json:"dt_txt"`
|
||||
}
|
||||
|
||||
// Forecast5WeatherData will hold returned data from queries
|
||||
type Forecast5WeatherData struct {
|
||||
// COD string `json:"cod"`
|
||||
// Message float64 `json:"message"`
|
||||
City City `json:"city"`
|
||||
Cnt int `json:"cnt"`
|
||||
List []Forecast5WeatherList `json:"list"`
|
||||
}
|
||||
|
||||
func (f *Forecast5WeatherData) Decode(r io.Reader) error {
|
||||
if err := json.NewDecoder(r).Decode(&f); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
147
vendor/github.com/briandowns/openweathermap/history.go
generated
vendored
Normal file
147
vendor/github.com/briandowns/openweathermap/history.go
generated
vendored
Normal file
@@ -0,0 +1,147 @@
|
||||
// Copyright 2015 Brian J. Downs
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package openweathermap
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// HistoricalParameters struct holds the (optional) fields to be
|
||||
// supplied for historical data requests.
|
||||
type HistoricalParameters struct {
|
||||
Start int64 // Data start (unix time, UTC time zone)
|
||||
End int64 // Data end (unix time, UTC time zone)
|
||||
Cnt int // Amount of returned data (one per hour, can be used instead of Data end)
|
||||
}
|
||||
|
||||
// Rain struct contains 3 hour data
|
||||
type Rain struct {
|
||||
ThreeH float64 `json:"3h"`
|
||||
}
|
||||
|
||||
// Snow struct contains 3 hour data
|
||||
type Snow struct {
|
||||
ThreeH float64 `json:"3h"`
|
||||
}
|
||||
|
||||
// WeatherHistory struct contains aggregate fields from the above
|
||||
// structs.
|
||||
type WeatherHistory struct {
|
||||
Main Main `json:"main"`
|
||||
Wind Wind `json:"wind"`
|
||||
Clouds Clouds `json:"clouds"`
|
||||
Weather []Weather `json:"weather"`
|
||||
Rain Rain `json:"rain"`
|
||||
Dt int `json:"dt"`
|
||||
}
|
||||
|
||||
// HistoricalWeatherData struct is where the JSON is unmarshaled to
|
||||
// when receiving data for a historical request.
|
||||
type HistoricalWeatherData struct {
|
||||
Message string `json:"message"`
|
||||
Cod int `json:"cod"`
|
||||
CityData int `json:"city_data"`
|
||||
CalcTime float64 `json:"calctime"`
|
||||
Cnt int `json:"cnt"`
|
||||
List []WeatherHistory `json:"list"`
|
||||
Unit string
|
||||
Key string
|
||||
*Settings
|
||||
}
|
||||
|
||||
// NewHistorical returns a new HistoricalWeatherData pointer with
|
||||
//the supplied arguments.
|
||||
func NewHistorical(unit, key string, options ...Option) (*HistoricalWeatherData, error) {
|
||||
h := &HistoricalWeatherData{
|
||||
Settings: NewSettings(),
|
||||
}
|
||||
|
||||
unitChoice := strings.ToUpper(unit)
|
||||
if !ValidDataUnit(unitChoice) {
|
||||
return nil, errUnitUnavailable
|
||||
}
|
||||
h.Unit = DataUnits[unitChoice]
|
||||
|
||||
var err error
|
||||
h.Key, err = setKey(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := setOptions(h.Settings, options); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return h, nil
|
||||
}
|
||||
|
||||
// HistoryByName will return the history for the provided location
|
||||
func (h *HistoricalWeatherData) HistoryByName(location string) error {
|
||||
response, err := h.client.Get(fmt.Sprintf(fmt.Sprintf(historyURL, "city?appid=%s&q=%s"), h.Key, url.QueryEscape(location)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
if err = json.NewDecoder(response.Body).Decode(&h); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// HistoryByID will return the history for the provided location ID
|
||||
func (h *HistoricalWeatherData) HistoryByID(id int, hp ...*HistoricalParameters) error {
|
||||
if len(hp) > 0 {
|
||||
response, err := h.client.Get(fmt.Sprintf(fmt.Sprintf(historyURL, "city?appid=%s&id=%d&type=hour&start%d&end=%d&cnt=%d"), h.Key, id, hp[0].Start, hp[0].End, hp[0].Cnt))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
if err = json.NewDecoder(response.Body).Decode(&h); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
response, err := h.client.Get(fmt.Sprintf(fmt.Sprintf(historyURL, "city?appid=%s&id=%d"), h.Key, id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
if err = json.NewDecoder(response.Body).Decode(&h); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// HistoryByCoord will return the history for the provided coordinates
|
||||
func (h *HistoricalWeatherData) HistoryByCoord(location *Coordinates, hp *HistoricalParameters) error {
|
||||
response, err := h.client.Get(fmt.Sprintf(fmt.Sprintf(historyURL, "appid=%s&lat=%f&lon=%f&start=%d&end=%d"), h.Key, location.Latitude, location.Longitude, hp.Start, hp.End))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
if err = json.NewDecoder(response.Body).Decode(&h); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
228
vendor/github.com/briandowns/openweathermap/openweathermap.go
generated
vendored
Normal file
228
vendor/github.com/briandowns/openweathermap/openweathermap.go
generated
vendored
Normal file
@@ -0,0 +1,228 @@
|
||||
// Copyright 2015 Brian J. Downs
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package openweathermap
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var errUnitUnavailable = errors.New("unit unavailable")
|
||||
var errLangUnavailable = errors.New("language unavailable")
|
||||
var errInvalidKey = errors.New("invalid api key")
|
||||
var errInvalidOption = errors.New("invalid option")
|
||||
var errInvalidHttpClient = errors.New("invalid http client")
|
||||
var errForecastUnavailable = errors.New("forecast unavailable")
|
||||
|
||||
// DataUnits represents the character chosen to represent the temperature notation
|
||||
var DataUnits = map[string]string{"C": "metric", "F": "imperial", "K": "internal"}
|
||||
var (
|
||||
baseURL = "http://api.openweathermap.org/data/2.5/weather?%s"
|
||||
iconURL = "http://openweathermap.org/img/w/%s"
|
||||
stationURL = "http://api.openweathermap.org/data/2.5/station?id=%d"
|
||||
forecast5Base = "http://api.openweathermap.org/data/2.5/forecast?appid=%s&%s&mode=json&units=%s&lang=%s&cnt=%d"
|
||||
forecast16Base = "http://api.openweathermap.org/data/2.5/forecast/daily?appid=%s&%s&mode=json&units=%s&lang=%s&cnt=%d"
|
||||
historyURL = "http://api.openweathermap.org/data/2.5/history/%s"
|
||||
pollutionURL = "http://api.openweathermap.org/pollution/v1/co/"
|
||||
uvURL = "http://api.openweathermap.org/data/2.5/"
|
||||
dataPostURL = "http://openweathermap.org/data/post"
|
||||
)
|
||||
|
||||
// LangCodes holds all supported languages to be used
|
||||
// inspried and sourced from @bambocher (github.com/bambocher)
|
||||
var LangCodes = map[string]string{
|
||||
"EN": "English",
|
||||
"RU": "Russian",
|
||||
"IT": "Italian",
|
||||
"ES": "Spanish",
|
||||
"SP": "Spanish",
|
||||
"UK": "Ukrainian",
|
||||
"UA": "Ukrainian",
|
||||
"DE": "German",
|
||||
"PT": "Portuguese",
|
||||
"RO": "Romanian",
|
||||
"PL": "Polish",
|
||||
"FI": "Finnish",
|
||||
"NL": "Dutch",
|
||||
"FR": "French",
|
||||
"BG": "Bulgarian",
|
||||
"SV": "Swedish",
|
||||
"SE": "Swedish",
|
||||
"TR": "Turkish",
|
||||
"HR": "Croatian",
|
||||
"CA": "Catalan",
|
||||
"ZH_TW": "Chinese Traditional",
|
||||
"ZH": "Chinese Simplified",
|
||||
"ZH_CN": "Chinese Simplified",
|
||||
}
|
||||
|
||||
// Config will hold default settings to be passed into the
|
||||
// "NewCurrent, NewForecast, etc}" functions.
|
||||
type Config struct {
|
||||
Mode string // user choice of JSON or XML
|
||||
Unit string // measurement for results to be displayed. F, C, or K
|
||||
Lang string // should reference a key in the LangCodes map
|
||||
APIKey string // API Key for connecting to the OWM
|
||||
Username string // Username for posting data
|
||||
Password string // Pasword for posting data
|
||||
}
|
||||
|
||||
// APIError returned on failed API calls.
|
||||
type APIError struct {
|
||||
Message string `json:"message"`
|
||||
COD string `json:"cod"`
|
||||
}
|
||||
|
||||
// Coordinates struct holds longitude and latitude data in returned
|
||||
// JSON or as parameter data for requests using longitude and latitude.
|
||||
type Coordinates struct {
|
||||
Longitude float64 `json:"lon"`
|
||||
Latitude float64 `json:"lat"`
|
||||
}
|
||||
|
||||
// Sys struct contains general information about the request
|
||||
// and the surrounding area for where the request was made.
|
||||
type Sys struct {
|
||||
Type int `json:"type"`
|
||||
ID int `json:"id"`
|
||||
Message float64 `json:"message"`
|
||||
Country string `json:"country"`
|
||||
Sunrise int `json:"sunrise"`
|
||||
Sunset int `json:"sunset"`
|
||||
}
|
||||
|
||||
// Wind struct contains the speed and degree of the wind.
|
||||
type Wind struct {
|
||||
Speed float64 `json:"speed"`
|
||||
Deg float64 `json:"deg"`
|
||||
}
|
||||
|
||||
// Weather struct holds high-level, basic info on the returned
|
||||
// data.
|
||||
type Weather struct {
|
||||
ID int `json:"id"`
|
||||
Main string `json:"main"`
|
||||
Description string `json:"description"`
|
||||
Icon string `json:"icon"`
|
||||
}
|
||||
|
||||
// Main struct contains the temperates, humidity, pressure for the request.
|
||||
type Main struct {
|
||||
Temp float64 `json:"temp"`
|
||||
TempMin float64 `json:"temp_min"`
|
||||
TempMax float64 `json:"temp_max"`
|
||||
Pressure float64 `json:"pressure"`
|
||||
SeaLevel float64 `json:"sea_level"`
|
||||
GrndLevel float64 `json:"grnd_level"`
|
||||
Humidity int `json:"humidity"`
|
||||
}
|
||||
|
||||
// Clouds struct holds data regarding cloud cover.
|
||||
type Clouds struct {
|
||||
All int `json:"all"`
|
||||
}
|
||||
|
||||
// return key
|
||||
// }
|
||||
func setKey(key string) (string, error) {
|
||||
if err := ValidAPIKey(key); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return key, nil
|
||||
}
|
||||
|
||||
// ValidDataUnit makes sure the string passed in is an accepted
|
||||
// unit of measure to be used for the return data.
|
||||
func ValidDataUnit(u string) bool {
|
||||
for d := range DataUnits {
|
||||
if u == d {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ValidLangCode makes sure the string passed in is an
|
||||
// acceptable lang code.
|
||||
func ValidLangCode(c string) bool {
|
||||
for d := range LangCodes {
|
||||
if c == d {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ValidDataUnitSymbol makes sure the string passed in is an
|
||||
// acceptable data unit symbol.
|
||||
func ValidDataUnitSymbol(u string) bool {
|
||||
for _, d := range DataUnits {
|
||||
if u == d {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ValidAPIKey makes sure that the key given is a valid one
|
||||
func ValidAPIKey(key string) error {
|
||||
if len(key) == 32 {
|
||||
return errors.New("invalid key")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckAPIKeyExists will see if an API key has been set.
|
||||
func (c *Config) CheckAPIKeyExists() bool { return len(c.APIKey) > 1 }
|
||||
|
||||
// Settings holds the client settings
|
||||
type Settings struct {
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
// NewSettings returns a new Setting pointer with default http client.
|
||||
func NewSettings() *Settings {
|
||||
return &Settings{
|
||||
client: http.DefaultClient,
|
||||
}
|
||||
}
|
||||
|
||||
// Optional client settings
|
||||
type Option func(s *Settings) error
|
||||
|
||||
// WithHttpClient sets custom http client when creating a new Client.
|
||||
func WithHttpClient(c *http.Client) Option {
|
||||
return func(s *Settings) error {
|
||||
if c == nil {
|
||||
return errInvalidHttpClient
|
||||
}
|
||||
s.client = c
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// setOptions sets Optional client settings to the Settings pointer
|
||||
func setOptions(settings *Settings, options []Option) error {
|
||||
for _, option := range options {
|
||||
if option == nil {
|
||||
return errInvalidOption
|
||||
}
|
||||
err := option(settings)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
82
vendor/github.com/briandowns/openweathermap/pollution.go
generated
vendored
Normal file
82
vendor/github.com/briandowns/openweathermap/pollution.go
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
package openweathermap
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// DateTimeAliases holds the alias the pollution API supports in lieu
|
||||
// of an ISO 8601 timestamp
|
||||
var DateTimeAliases = []string{"current"}
|
||||
|
||||
// ValidAlias checks to make sure the given alias is a valid one
|
||||
func ValidAlias(alias string) bool {
|
||||
for _, i := range DateTimeAliases {
|
||||
if i == alias {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// PollutionData holds the pollution specific data from the call
|
||||
type PollutionData struct {
|
||||
Precision float64 `json:"precision"`
|
||||
Pressure float64 `json:"pressure"`
|
||||
Value float64 `json:"value"`
|
||||
}
|
||||
|
||||
// PollutionParameters holds the parameters needed to make
|
||||
// a call to the pollution API
|
||||
type PollutionParameters struct {
|
||||
Location Coordinates
|
||||
Datetime string // this should be either ISO 8601 or an alias
|
||||
}
|
||||
|
||||
// Pollution holds the data returnd from the pollution API
|
||||
type Pollution struct {
|
||||
Time string `json:"time"`
|
||||
Location Coordinates `json:"location"`
|
||||
Data []PollutionData `json:"data"`
|
||||
Key string
|
||||
*Settings
|
||||
}
|
||||
|
||||
// NewPollution creates a new reference to Pollution
|
||||
func NewPollution(key string, options ...Option) (*Pollution, error) {
|
||||
k, err := setKey(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p := &Pollution{
|
||||
Key: k,
|
||||
Settings: NewSettings(),
|
||||
}
|
||||
|
||||
if err := setOptions(p.Settings, options); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// PollutionByParams gets the pollution data based on the given parameters
|
||||
func (p *Pollution) PollutionByParams(params *PollutionParameters) error {
|
||||
url := fmt.Sprintf("%s%s,%s/%s.json?appid=%s",
|
||||
pollutionURL,
|
||||
strconv.FormatFloat(params.Location.Latitude, 'f', -1, 64),
|
||||
strconv.FormatFloat(params.Location.Longitude, 'f', -1, 64),
|
||||
params.Datetime,
|
||||
p.Key)
|
||||
response, err := p.client.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
if err = json.NewDecoder(response.Body).Decode(&p); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
80
vendor/github.com/briandowns/openweathermap/station.go
generated
vendored
Normal file
80
vendor/github.com/briandowns/openweathermap/station.go
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
// Copyright 2015 Brian J. Downs
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package openweathermap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Slice of type string of the valid parameters to be sent from a station.
|
||||
// The API refers to this data as the "Weather station data transmission protocol"
|
||||
var StationDataParameters = []string{
|
||||
"wind_dir", // Wind direction
|
||||
"wind_speed", // Wind speed
|
||||
"wind_gust", // Wind gust speed
|
||||
"temp", // Temperature
|
||||
"humidity", // Relative humidty
|
||||
"pressure", // Atmospheric pressure
|
||||
"rain_1h", // Rain in the last hour
|
||||
"rain_24h", // Rain in the last 24 hours
|
||||
"rain_today", // Rain since midnight
|
||||
"snow", // Snow in the last 24 hours
|
||||
"lum", // Brightness
|
||||
"lat", // Latitude
|
||||
"long", // Longitude
|
||||
"alt", // Altitude
|
||||
"radiation", // Radiation
|
||||
"dewpoint", // Dew point
|
||||
"uv", // UV index
|
||||
"name", // Weather station name
|
||||
}
|
||||
|
||||
// ValidateStationDataParameter will make sure that whatever parameter
|
||||
// supplied is one that can actually be used in the POST request.
|
||||
func ValidateStationDataParameter(param string) bool {
|
||||
for _, p := range StationDataParameters {
|
||||
if param == p {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// ConvertToURLValues will convert a map to a url.Values instance. We're
|
||||
// taking a map[string]string instead of something more type specific since
|
||||
// the url.Values instance only takes strings to create the URL values.
|
||||
func ConvertToURLValues(data map[string]string) string {
|
||||
v := url.Values{}
|
||||
|
||||
for key, val := range data {
|
||||
v.Set(key, val)
|
||||
}
|
||||
|
||||
return v.Encode()
|
||||
}
|
||||
|
||||
// SendStationData will send an instance the provided url.Values to the
|
||||
// provided URL.
|
||||
func SendStationData(data url.Values) {
|
||||
resp, err := http.PostForm(dataPostURL, data)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
fmt.Println(resp.Body)
|
||||
}
|
||||
170
vendor/github.com/briandowns/openweathermap/uv.go
generated
vendored
Normal file
170
vendor/github.com/briandowns/openweathermap/uv.go
generated
vendored
Normal file
@@ -0,0 +1,170 @@
|
||||
package openweathermap
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
var errInvalidUVIndex = errors.New("invalid UV index value")
|
||||
|
||||
// UVDataPoints holds the UV specific data
|
||||
type UVDataPoints struct {
|
||||
DT int64 `json:"dt"`
|
||||
Value float64 `json:"value"`
|
||||
}
|
||||
|
||||
// UV contains the response from the OWM UV API
|
||||
type UV struct {
|
||||
Coord []float64 `json:"coord"`
|
||||
Data []UVDataPoints `json:"data,omitempty"`
|
||||
/*Data []struct {
|
||||
DT int64 `json:"dt"`
|
||||
Value float64 `json:"value"`
|
||||
} `json:"data,omitempty"`*/
|
||||
DT int64 `json:"dt,omitempty"`
|
||||
Value float64 `json:"value,omitempty"`
|
||||
Key string
|
||||
*Settings
|
||||
}
|
||||
|
||||
// NewUV creates a new reference to UV
|
||||
func NewUV(key string, options ...Option) (*UV, error) {
|
||||
k, err := setKey(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
u := &UV{
|
||||
Key: k,
|
||||
Settings: NewSettings(),
|
||||
}
|
||||
|
||||
if err := setOptions(u.Settings, options); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return u, nil
|
||||
}
|
||||
|
||||
// Current gets the current UV data for the given coordinates
|
||||
func (u *UV) Current(coord *Coordinates) error {
|
||||
response, err := u.client.Get(fmt.Sprintf("%suvi?lat=%f&lon=%f&appid=%s", uvURL, coord.Latitude, coord.Longitude, u.Key))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
if err = json.NewDecoder(response.Body).Decode(&u); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Historical gets the historical UV data for the coordinates and times
|
||||
func (u *UV) Historical(coord *Coordinates, start, end time.Time) error {
|
||||
response, err := u.client.Get(fmt.Sprintf("%shistory?lat=%f&lon=%f&start=%d&end=%d&appid=%s", uvURL, coord.Latitude, coord.Longitude, start.Unix(), end.Unix(), u.Key))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
if err = json.NewDecoder(response.Body).Decode(&u); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UVIndexInfo
|
||||
type UVIndexInfo struct {
|
||||
// UVIndex holds the range of the index
|
||||
UVIndex []float64
|
||||
|
||||
// MGC represents the Media graphic color
|
||||
MGC string
|
||||
|
||||
// Risk of harm from unprotected sun exposure, for the average adult
|
||||
Risk string
|
||||
|
||||
// RecommendedProtection contains information on what a person should
|
||||
// do when outside in the associated UVIndex
|
||||
RecommendedProtection string
|
||||
}
|
||||
|
||||
// UVData contains data in regards to UV index ranges, rankings, and steps for protection
|
||||
var UVData = []UVIndexInfo{
|
||||
{
|
||||
UVIndex: []float64{0, 2.9},
|
||||
MGC: "Green",
|
||||
Risk: "Low",
|
||||
RecommendedProtection: "Wear sunglasses on bright days; use sunscreen if there is snow on the ground, which reflects UV radiation, or if you have particularly fair skin.",
|
||||
},
|
||||
{
|
||||
UVIndex: []float64{3, 5.9},
|
||||
MGC: "Yellow",
|
||||
Risk: "Moderate",
|
||||
RecommendedProtection: "Take precautions, such as covering up, if you will be outside. Stay in shade near midday when the sun is strongest.",
|
||||
},
|
||||
{
|
||||
UVIndex: []float64{6, 7.9},
|
||||
MGC: "Orange",
|
||||
Risk: "High",
|
||||
RecommendedProtection: "Cover the body with sun protective clothing, use SPF 30+ sunscreen, wear a hat, reduce time in the sun within three hours of solar noon, and wear sunglasses.",
|
||||
},
|
||||
{
|
||||
UVIndex: []float64{8, 10.9},
|
||||
MGC: "Red",
|
||||
Risk: "Very high",
|
||||
RecommendedProtection: "Wear SPF 30+ sunscreen, a shirt, sunglasses, and a wide-brimmed hat. Do not stay in the sun for too long.",
|
||||
},
|
||||
{
|
||||
UVIndex: []float64{11},
|
||||
MGC: "Violet",
|
||||
Risk: "Extreme",
|
||||
RecommendedProtection: "Take all precautions: Wear SPF 30+ sunscreen, a long-sleeved shirt and trousers, sunglasses, and a very broad hat. Avoid the sun within three hours of solar noon.",
|
||||
},
|
||||
}
|
||||
|
||||
// UVInformation provides information on the given UV data which includes the severity
|
||||
// and "Recommended protection"
|
||||
func (u *UV) UVInformation() ([]UVIndexInfo, error) {
|
||||
switch {
|
||||
case u.Value != 0:
|
||||
switch {
|
||||
case u.Value < 2.9:
|
||||
return []UVIndexInfo{UVData[0]}, nil
|
||||
case u.Value > 3 && u.Value < 5.9:
|
||||
return []UVIndexInfo{UVData[1]}, nil
|
||||
case u.Value > 6 && u.Value < 7.9:
|
||||
return []UVIndexInfo{UVData[2]}, nil
|
||||
case u.Value > 8 && u.Value < 10.9:
|
||||
return []UVIndexInfo{UVData[3]}, nil
|
||||
case u.Value >= 11:
|
||||
return []UVIndexInfo{UVData[4]}, nil
|
||||
default:
|
||||
return nil, errInvalidUVIndex
|
||||
}
|
||||
|
||||
case len(u.Data) > 0:
|
||||
var uvi []UVIndexInfo
|
||||
for _, i := range u.Data {
|
||||
switch {
|
||||
case i.Value < 2.9:
|
||||
uvi = append(uvi, UVData[0])
|
||||
case i.Value > 3 && u.Value < 5.9:
|
||||
uvi = append(uvi, UVData[1])
|
||||
case i.Value > 6 && u.Value < 7.9:
|
||||
uvi = append(uvi, UVData[2])
|
||||
case i.Value > 8 && u.Value < 10.9:
|
||||
uvi = append(uvi, UVData[3])
|
||||
case i.Value >= 11:
|
||||
uvi = append(uvi, UVData[4])
|
||||
default:
|
||||
return nil, errInvalidUVIndex
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
Reference in New Issue
Block a user