weatherapi

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

weatherapi implements an API client for WeatherAPI (https://www.weatherapi.com/docs/)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Astro added in v1.0.6

type Astro struct {
	SunRise          string `json:"sunrise"`
	SunSet           string `json:"sunset"`
	MoonRise         string `json:"moonrise"`
	MoonSet          string `json:"moonset"`
	MoonPhase        string `json:"moon_phase"`
	MoonIllumination int    `json:"moon_illumination"`
	IsMoonUp         int    `json:"is_moon_up"`
	IsSunUp          int    `json:"is_sun_up"`
}

type Client

type Client struct {
	*client.Client
	// contains filtered or unexported fields
}

func New

func New(ApiKey string, opts ...client.ClientOpt) (*Client, error)

Create a new client

func (*Client) Current

func (c *Client) Current(q string) (Weather, error)

Current weather

func (*Client) Forecast added in v1.0.6

func (c *Client) Forecast(q string, opts ...Opt) (Forecast, error)

Forecast weather

func (*Client) Tools added in v1.0.10

func (c *Client) Tools() []agent.Tool

Return all the agent tools for the weatherapi

type Conditions added in v1.0.6

type Conditions struct {
	TempC     float64 `json:"temp_c"`
	TempF     float64 `json:"temp_f"`
	IsDay     int     `json:"is_day"` // Whether to show day condition icon (1) or night icon (0)
	Condition struct {
		Text string `json:"text"`
		Icon string `json:"icon"`
		Code int    `json:"code"`
	} `json:"condition"`
	WindMph    float64 `json:"wind_mph"`
	WindKph    float64 `json:"wind_kph"`
	WindDegree int     `json:"wind_degree"`
	WindDir    string  `json:"wind_dir"`
	PressureMb float64 `json:"pressure_mb"`
	PressureIn float64 `json:"pressure_in"`
	PrecipMm   float64 `json:"precip_mm"`
	PrecipIn   float64 `json:"precip_in"`
	Humidity   int     `json:"humidity"`
	Cloud      int     `json:"cloud"`
	FeelslikeC float64 `json:"feelslike_c"`
	FeelslikeF float64 `json:"feelslike_f"`
	VisKm      float64 `json:"vis_km"`
	VisMiles   float64 `json:"vis_miles"`
	Uv         float64 `json:"uv"`
	GustMph    float64 `json:"gust_mph"`
	GustKph    float64 `json:"gust_kph"`
}

type CurrentConditions added in v1.0.6

type CurrentConditions struct {
	LastUpdatedEpoch int64 `json:"last_updated_epoch"`
	LastUpdated      Time  `json:"last_updated,omitempty"`
	Conditions
}

type Day added in v1.0.6

type Day struct {
	MaxTempC            float64 `json:"maxtemp_c"`
	MaxTempF            float64 `json:"maxtemp_f"`
	MinTempC            float64 `json:"mintemp_c"`
	MinTempF            float64 `json:"mintemp_f"`
	AvgTempC            float64 `json:"avgtemp_c"`
	AvgTempF            float64 `json:"avgtemp_f"`
	MaxWindMph          float64 `json:"maxwind_mph"`
	MaxWindKph          float64 `json:"maxwind_kph"`
	TotalPrecipMm       float64 `json:"totalprecip_mm"`
	TotalPrecipIn       float64 `json:"totalprecip_in"`
	TotalSnowCm         float64 `json:"totalsnow_cm"`
	AvgVisKm            float64 `json:"avgvis_km"`
	AvgVisMiles         float64 `json:"avgvis_miles"`
	AvgHumidity         int     `json:"avghumidity"`
	WillItRain          int     `json:"daily_will_it_rain"`
	WillItSnow          int     `json:"daily_will_it_snow"`
	ChanceOfRainPercent int     `json:"daily_chance_of_rain"`
	ChanceOfSnowPercent int     `json:"daily_chance_of_snow"`
	Uv                  float32 `json:"uv"`
	Condition           struct {
		Text string `json:"text"`
		Icon string `json:"icon"`
		Code int    `json:"code"`
	} `json:"condition"`
}

type Forecast added in v1.0.6

type Forecast struct {
	Id       int                `json:"custom_id,omitempty"`
	Query    string             `json:"q,omitempty"`
	Location *Location          `json:"location,omitempty"`
	Current  *CurrentConditions `json:"current,omitempty"`
	Forecast struct {
		Day []*ForecastDay `json:"forecastday"`
	} `json:"forecast,omitempty"`
}

func (Forecast) String added in v1.0.6

func (f Forecast) String() string

type ForecastConditions added in v1.0.6

type ForecastConditions struct {
	TimeEpoch int64 `json:"time_epoch"`
	Time      Time  `json:"time,omitempty"`
	Conditions
}

type ForecastDay added in v1.0.6

type ForecastDay struct {
	Date      string                `json:"date"`
	DateEpoch int64                 `json:"date_epoch"`
	Day       *Day                  `json:"day"`
	Hour      []*ForecastConditions `json:"hour"`
	Astro     *Astro                `json:"astro"`
}

type Location

type Location struct {
	Name           string  `json:"name"`
	Region         string  `json:"region"`
	Country        string  `json:"country"`
	Lat            float64 `json:"lat"`
	Lon            float64 `json:"lon"`
	Timezone       string  `json:"timezone"`
	LocaltimeEpoch int64   `json:"localtime_epoch"`
	Localtime      Time    `json:"localtime,omitempty"`
}

type Opt added in v1.0.6

type Opt func(*options) error

func OptAirQuality added in v1.0.6

func OptAirQuality() Opt

Get air quality data

func OptAlerts added in v1.0.6

func OptAlerts() Opt

Get weather alert data

func OptDays added in v1.0.6

func OptDays(days int) Opt

Number of days of weather forecast. Value ranges from 1 to 10

type Time

type Time struct {
	time.Time
}

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

type Weather

type Weather struct {
	Id       int                `json:"custom_id,omitempty"`
	Query    string             `json:"q,omitempty"`
	Location *Location          `json:"location,omitempty"`
	Current  *CurrentConditions `json:"current,omitempty"`
}

func (Weather) String

func (w Weather) String() string

Jump to

Keyboard shortcuts

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