owm

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2020 License: Apache-2.0 Imports: 6 Imported by: 2

README

go-owm

Travis (master)

go-owm is a library for the OpenWeatherMap "One Call API", providing current weather as well as hourly and daily forecasts. See the OWM API documentation for a description of the provided elements.

Usage

import (
    "fmt"
    "github.com/dschanoeh/go-owm"
    )

func main() {
    w, err := owm.GetWeather(52.41467, 10.74063, "OWM_API_KEY")

    fmt.printf("The current temperature is: %f", w.Current.Temperature)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CurrentData

type CurrentData struct {
	Timestamp     int64                `json:"dt"`
	Sunrise       int64                `json:"sunrise"`
	Sunset        int64                `json:"sunset"`
	Temperature   float64              `json:"temp"`
	FeelsLike     float64              `json:"feels_like"`
	Pressure      float64              `json:"pressure"`
	Humidity      uint8                `json:"humidity"`
	DewPoint      float64              `json:"dew_point"`
	UVI           float64              `json:"uvi"`
	Clouds        uint8                `json:"clouds"`
	Visiblity     uint64               `json:"visibility"`
	WindSpeed     float64              `json:"wind_speed"`
	WindDirection float64              `json:"wind_deg"`
	Weather       []WeatherDescription `json:"weather"`
	Rain          Rain                 `json:"rain"`
	Snow          Snow                 `json:"snow"`
	ParsedTime    *time.Time
}

CurrentData represents the current weather conditions

type DailyWeatherSlice

type DailyWeatherSlice struct {
	Timestamp     int64                `json:"dt"`
	Sunrise       int64                `json:"sunrise"`
	Sunset        int64                `json:"sunset"`
	Temperature   TemperatureStats     `json:"temp"`
	FeelsLike     FeelsLikeStats       `json:"feels_like"`
	Pressure      float64              `json:"pressure"`
	Humidity      uint8                `json:"humidity"`
	DewPoint      float64              `json:"dew_point"`
	WindSpeed     float64              `json:"wind_speed"`
	WindDirection float64              `json:"wind_deg"`
	Weather       []WeatherDescription `json:"weather"`
	Clouds        uint8                `json:"clouds"`
	Rain          float64              `json:"rain"`
	Snow          float64              `json:"snow"`
	UVI           float64              `json:"uvi"`
	ParsedTime    *time.Time
}

DailyWeatherSlice represents one element in the daily forecast

type FeelsLikeStats

type FeelsLikeStats struct {
	Day     float64 `json:"day"`
	Night   float64 `json:"night"`
	Evening float64 `json:"eve"`
	Morning float64 `json:"morn"`
}

FeelsLikeStats contains daily feels-like temperature statistics

type HourlyWeatherSlice

type HourlyWeatherSlice struct {
	Timestamp     int64                `json:"dt"`
	Temperature   float64              `json:"temp"`
	FeelsLike     float64              `json:"feels_like"`
	Pressure      float64              `json:"pressure"`
	Humidity      uint8                `json:"humidity"`
	DewPoint      float64              `json:"dew_point"`
	Clouds        uint8                `json:"clouds"`
	WindSpeed     float64              `json:"wind_speed"`
	WindDirection float64              `json:"wind_deg"`
	Weather       []WeatherDescription `json:"weather"`
	Rain          Rain                 `json:"rain"`
	Snow          Snow                 `json:"snow"`
	ParsedTime    *time.Time
}

HourlyWeatherSlice represents one element in the hourly forecast

type Rain

type Rain struct {
	OneHour float64 `json:"1h"`
}

Rain contains rain data

type Snow

type Snow struct {
	OneHour float64 `json:"1h"`
}

Snow contains snow data

type TemperatureStats

type TemperatureStats struct {
	Day     float64 `json:"day"`
	Min     float64 `json:"min"`
	Max     float64 `json:"max"`
	Night   float64 `json:"night"`
	Evening float64 `json:"eve"`
	Morning float64 `json:"morn"`
}

TemperatureStats contains daily temperature statistics

type WeatherData

type WeatherData struct {
	Latitude       float64              `json:"lat"`
	Longitude      float64              `json:"lon"`
	Timezone       string               `json:"timezone"`
	TimezoneOffset uint16               `json:"timezone_offset"`
	Current        CurrentData          `json:"current"`
	HourlyWeather  []HourlyWeatherSlice `json:"hourly"`
	DailyWeather   []DailyWeatherSlice  `json:"daily"`
	ParsedTimeZone *time.Location
}

WeatherData holds the weather information returned by the OWM API

func GetWeather

func GetWeather(lat float64, lon float64, APIKey string) (*WeatherData, error)

GetWeather performs an API call for the location given through lat,lon using the APIkey

func (WeatherData) AverageFeelsLikeTill

func (weather WeatherData) AverageFeelsLikeTill(referenceTime time.Time) float64

AverageFeelsLikeTill returns the average feels like temperature from the beginning of the data range till referenceTime

func (WeatherData) AverageTemperatureTill

func (weather WeatherData) AverageTemperatureTill(referenceTime time.Time) float64

AverageTemperatureTill returns the average temperature from the beginning of the data range till referenceTime

func (WeatherData) CumulativePrecipitationTill

func (weather WeatherData) CumulativePrecipitationTill(referenceTime time.Time) float64

CumulativePrecipitationTill returns the cumulative precipitation from the beginning of the data range till referenceTime

func (WeatherData) String

func (weather WeatherData) String() string

func (WeatherData) TemperatureAt

func (weather WeatherData) TemperatureAt(referenceTime time.Time) float64

TemperatureAt returns the temperature for the given referenceTime

func (*WeatherData) WeatherAt

func (weather *WeatherData) WeatherAt(referenceTime time.Time) *HourlyWeatherSlice

WeatherAt returns the weather closest to referenceTime

func (WeatherData) WeatherTill

func (weather WeatherData) WeatherTill(referenceTime time.Time) []HourlyWeatherSlice

WeatherTill returns all weather slices from the beginning of the forecast to the given time

type WeatherDescription

type WeatherDescription struct {
	ID          uint16 `json:"id"`
	Main        string `json:"main"`
	Description string `json:"description"`
	Icon        string `json:"icon"`
}

WeatherDescription summarizes the current weather for human presentation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL