godock: github.com/sqp/godock/libs/get/weather Index | Files

package weather

import "github.com/sqp/godock/libs/get/weather"

Package weather provides a data source for weather informations.

Index

Package Files

backend_weatherCom.go weather.go

Constants

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.

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

URL for webpages to open.

const DegreeSymbol = "°"

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

Variables

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

Weather errors.

func FindLocation Uses

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

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

func FormatField Uses

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 Uses

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 Uses

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

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

type BackendID Uses

type BackendID int

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

const (
    BackendWeatherCom BackendID = iota
)

Weather backends.

type Config Uses

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 Uses

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 Uses

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

Fields format a list of fields from the template.

func (*Current) Format Uses

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

Format returns the template formatted string for today.

type Day Uses

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 Uses

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 Uses

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

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

func (*Forecast) Fields Uses

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

Fields format a list of fields from the template.

func (*Forecast) Format Uses

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 Uses

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.

type Part Uses

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 Uses

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 Uses

func New() Weather

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

Package weather imports 10 packages (graph) and is imported by 1 packages. Updated 2017-10-21. Refresh now. Tools for package owners.