View Source NOAA.Observations.State (NOAA Observations v0.4.57)

Fetches the stations for a US state/territory code.

Summary

Types

US state/territory code

Functions

Fetches the stations for a US state/territory code.

Types

@type code() :: String.t()

US state/territory code

Functions

Link to this function

stations(code, url_templates)

View Source
@spec stations(code(), Keyword.t()) ::
  {:ok, [NOAA.Observations.Station.t()]} | {:error, String.t()}

Fetches the stations for a US state/territory code.

Returns a tuple of either {:ok, [station]} or {:error, text}.

Parameters

  • code - US state/territory code
  • url_templates - URL templates

Examples

iex> alias NOAA.Observations.State
iex> url_templates = [
...>   state:
...>     "https://w1.weather.gov/xml/current_obs/seek.php?state=" <>
...>       "<%=state%>&Find=Find"
...> ]
iex> {:ok, stations} = State.stations("vt", url_templates)
iex> %{"KFSO" => name} = Map.new(stations)
iex> name
"Franklin County State Airport"

iex> alias NOAA.Observations.State
iex> url_templates = [
...>   state:
...>     "http://w1.weather.gov/xml/current_obs/seek.php?state=" <>
...>       "<%=state%>&Find=Find"
...> ]
iex> {:error, text} = State.stations("vt", url_templates)
iex> text
"status code 301 ⇒ Moved Permanently"

iex> alias NOAA.Observations.State
iex> url_templates = [
...>   state:
...>     "https://www.weather.gov/xml/current_obs/seek.php?state=" <>
...>       "<%=state%>&Find=Find"
...> ]
iex> {:error, text} = State.stations("vt", url_templates)
iex> text
"status code 302 ⇒ Found"

iex> alias NOAA.Observations.State
iex> url_templates = [
...>   state:
...>     "https://w1.weather.gov/xml/past_obs/seek.php?state=" <>
...>       "<%=state%>&Find=Find"
...> ]
iex> {:error, text} = State.stations("vt", url_templates)
iex> text
"status code 404 ⇒ Not Found"

iex> alias NOAA.Observations.State
iex> url_templates = [
...>   state:
...>     "htp://w1.weather.gov/xml/current_obs/seek.php?state=" <>
...>       "<%=state%>&Find=Find"
...> ]
iex> {:error, text} = State.stations("vt", url_templates)
iex> text
"reason => :nxdomain"

iex> alias NOAA.Observations.State
iex> url_templates = [state: "http://localhost:1"]
iex> {:error, text} = State.stations("vt", url_templates)
iex> text
"reason => :econnrefused"