View Source NOAA.Observations.Station (NOAA Observations v0.4.57)
Fetches the latest observation for a given NOAA station.
Summary
Functions
Fetches the latest observation for a given NOAA station
.
Types
Functions
@spec observation(t(), NOAA.Observations.State.code(), Keyword.t()) :: {:ok, observation()} | {:error, String.t()}
Fetches the latest observation for a given NOAA station
.
Returns either tuple {:ok, observation}
or tuple {:error, text}
.
Parameters
{id, name}
- NOAA stationurl_templates
- URL templates
Examples
iex> alias NOAA.Observations.Station
iex> url_templates = [
...> station:
...> "https://w1.weather.gov/xml/current_obs/display.php?stid=" <>
...> "<%=station%>"
...> ]
iex> {:ok, observation} =
...> Station.observation({"KFSO", "KFSO name"}, "vt", url_templates)
iex> is_map(observation) and
...> is_binary(observation["temp_c"]) and
...> is_binary(observation["wind_mph"])
true
iex> alias NOAA.Observations.Station
iex> url_templates = [
...> station:
...> "htp://w1.weather.gov/xml/current_obs/display.php?stid=" <>
...> "<%=station%>"
...> ]
iex> {:error, text} =
...> Station.observation({"KFSO", "KFSO name"}, "vt", url_templates)
iex> text
"reason => :nxdomain"
iex> alias NOAA.Observations.Station
iex> url_templates = [
...> station:
...> "https://w1.weather.gov/xml/past_obs/display.php?stid=" <>
...> "<%=station%>"
...> ]
iex> {:error, text} =
...> Station.observation({"KFSO", "KFSO name"}, "vt", url_templates)
iex> text
"status code 404 ⇒ Not Found"