weather

package
v0.0.0-...-0caaa62 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2017 License: GPL-3.0-or-later Imports: 10 Imported by: 0

Documentation

Overview

Package weather provides a data source for weather informations.

Index

Constants

View Source
const (
	WeatherComURLBase        = "http://wxdata.weather.com/wxdata"
	WeatherComSuffixCurrent  = "/weather/local/%s?cc=*"
	WeatherComSuffixForecast = "/weather/local/%s?dayf=%d"
	WeatherComSuffixCelcius  = "&unit=m"
)

URL for backend data.

View Source
const (
	URLWeatherComHour   = "http://www.weather.com/weather/hourbyhour/graph/%s"
	URLWeatherComDetail = "http://www.weather.com/weather/tenday/%s"
)

URL for webpages to open.

View Source
const DegreeSymbol = "°"

DegreeSymbol needs to be added before unit temperature (C or F).

Variables

View Source
var (
	ErrMissingConfObject   = errors.New("weather #1: conf object missing")
	ErrMissingLocationCode = errors.New("weather #2: location missing")
	ValueMissing           = "N/A"
)

Weather errors.

Functions

func FormatField

func FormatField(template *cdtype.Template, list []string, data interface{}) (string, error)

FormatField formats a list of fields with the given template.

It's a callback from the template, where the list of fields to display is set. With this method, we can translate titles, align data and allow custom templating for the user.

func FormatSun

func FormatSun(sunrise, sunset string, time24H bool) (sunrise2, sunset2 string, isNight bool, e error)

FormatSun formats sunrise and sunset time and tells if it's the night.

func FormatTemplate

func FormatTemplate(template *cdtype.Template, funcName string, data interface{}) (string, error)

FormatTemplate formats the given data object with the given template function name.

Types

type BackendID

type BackendID int

BackendID represents the reference for a backend source of weather data.

const (
	BackendWeatherCom BackendID = iota
)

Weather backends.

type Config

type Config struct {
	LocationCode       string // hidden in conf
	UseCelcius         bool   // format temp celcius or fahrenheit
	Time24H            bool   // format time 24H or 12H (AM/PM).
	DisplayCurrentIcon bool   // current weather.
	NbDays             int    // forecast (next days).
}

Config defines the weather data source configuration.

type Current

type Current struct {
	UnitDistance string `xml:"head>ud"`
	UnitPressure string `xml:"head>up"`
	UnitSpeed    string `xml:"head>us"`
	UnitTemp     string `xml:"head>ut"`

	LocName string `xml:"loc>dnam"`
	Sunrise string `xml:"loc>sunr"`
	Sunset  string `xml:"loc>suns"`

	UpdateTime          string `xml:"cc>lsup"`
	Observatory         string `xml:"cc>obst"`
	TempReal            int    `xml:"cc>tmp"`
	TempFelt            int    `xml:"cc>flik"`
	WeatherDescription  string `xml:"cc>t"`
	WeatherIcon         string `xml:"cc>icon"`
	Pressure            string `xml:"cc>bar>r"`
	PressureDescription string `xml:"cc>bar>d"`
	WindSpeed           string `xml:"cc>wind>s"`
	WindDirection       string `xml:"cc>wind>t"`
	Humidity            string `xml:"cc>hmid"`
	Visibility          string `xml:"cc>vis"`
	MoonIcon            int    `xml:"cc>moon>icon"`
	UVi                 int    `xml:"cc>uv>i"`
	UVDescription       string `xml:"cc>uv>t"`

	// Template stuff
	Template      *cdtype.Template // template for the field formater.
	TxtUpdateTime string           // formated (h24) UpdateTime
	TxtSunrise    string           // formated (h24) Sunrise
	TxtSunset     string           // formated (h24) Sunset
	IsNight       bool
}

Current contains weather data for the current day.

func (*Current) Fields

func (wc *Current) Fields(list ...string) (string, error)

Fields format a list of fields from the template.

func (*Current) Format

func (wc *Current) Format(template *cdtype.Template) (string, error)

Format returns the template formatted string for today.

type Day

type Day struct {
	Date     string `xml:"dt,attr"`
	DayName  string `xml:"t,attr"`
	DayCount string `xml:"d,attr"`
	Sunrise  string `xml:"sunr"`
	Sunset   string `xml:"suns"`
	TempMin  string `xml:"low"`
	TempMax  string `xml:"hi"`

	Part []Part `xml:"part"`

	// Template stuff
	MonthDay   int    // day number in the month.
	TxtSunrise string // formated (h24) Sunrise
	TxtSunset  string // formated (h24) Sunset
}

Day defines weather forecast data for one of the following day.

type Forecast

type Forecast struct {
	Ver          string `xml:"ver,attr"`
	Ur           string `xml:"head>ur"`
	UnitDistance string `xml:"head>ud"`
	UnitPressure string `xml:"head>up"`
	UnitSpeed    string `xml:"head>us"`
	UnitTemp     string `xml:"head>ut"`
	Locale       string `xml:"head>locale"`
	Form         string `xml:"head>form"`
	Tm           string `xml:"loc>tm"`
	LocName      string `xml:"loc>dnam"`
	Lon          string `xml:"loc>lon"`
	Lat          string `xml:"loc>lat"`
	Zone         string `xml:"loc>zone"`

	UpdateTime string `xml:"dayf>lsup"`
	Days       []Day  `xml:"dayf>day"`

	// Template stuff
	Template *cdtype.Template // template for the field formater.
	*Day                      // requested day
	*Part                     // requested part of day
}

Forecast defines weather forecast data for the following days.

func (*Forecast) DayPart

func (wc *Forecast) DayPart(dayNum int, getNight bool) *Part

DayPart returns a part (day or night) weather forecast data.

func (*Forecast) Fields

func (wc *Forecast) Fields(list ...string) (string, error)

Fields format a list of fields from the template.

func (*Forecast) Format

func (wc *Forecast) Format(template *cdtype.Template, dayNum int, time24H bool) (string, error)

Format returns the template formatted string for the given day.

type Loc

type Loc struct {
	Type string `xml:"type,attr"`
	Name string `xml:",chardata"`
	ID   string `xml:"id,attr"`
}

Loc represents a location found in the search location query.

func FindLocation

func FindLocation(locationName string) ([]Loc, error)

FindLocation asks the server the list of locations matching the given name.

type Part

type Part struct {
	Period             string `xml:"p,attr"`
	WeatherDescription string `xml:"t"`
	WindDegree         string `xml:"wind>d"`
	WindSpeed          string `xml:"wind>s"`
	WindDirection      string `xml:"wind>t"`
	Humidity           string `xml:"hmid"`
	WeatherIcon        string `xml:"icon"`
	PrecipitationProba string `xml:"ppcp"`
	WeatherShortDesc   string `xml:"bt"`
	Gust               string `xml:"wind>gust"`
}

Part defines weather forecast data for one part (day or night) of a following day.

type Search struct {
	Ver string `xml:"ver,attr"`
	Loc []Loc  `xml:"loc"`
}

Search represents the xml base struct for the search location query.

type Weather

type Weather interface {
	WebpageURL(numDay int) string
	Get() chan error
	Current() *Current
	Forecast() *Forecast
	SetConfig(*Config)
	Clear()
}

Weather defines the usage of the weather data source.

func New

func New() Weather

New creates a new weather data source for the given backend.

Jump to

Keyboard shortcuts

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