2.0.3 • Published 3 years ago

@withaspark/weather v2.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Weather

Current weather and forecast fetching script

Install

NPM

npm install --save @withaspark/weather

Usage

Script

var Weather = require('path/to/src/withaspark.weather.js')({ station: "KJAX", cache_lifetime: 10 });

console.log(Weather.getTemperature());
// 62

console.log(Weather.getSunrise());
// "2019-04-28T06:47:22.419-04:00"

console.log(Weather.get());
// { station: 'KJAX',
//   sunrise: '2019-04-28T06:47:22.419-04:00',
//   sunset: '2019-04-28T20:03:36.240-04:00',
//   timestamp: '2019-04-28T03:56:00+00:00',
//   raw: 'KJAX 280356Z 00000KT 10SM CLR 17/12 A3003 RMK AO2 SLP169 T01720122 $',
//   coordinates: [ 30.5, -81.7 ],
//   elevation: 29,
//   text: 'Clear',
//   temperature: 62,
//   dewpoint: 53,
//   windDirection: 0,
//   windSpeed: 0,
//   pressure: 762,
//   visibility: 9,
//   precipitation: 0,
//   humidity: 72,
//   feelsLike: 32,
//   alerts: '',
//   sunIcon: \uf02e,
//   conditionIcon: \uf02e,
//   isDay: 0,
//   isNight: 1,
//   isSunrise: 0,
//   isSunset: 0 }

Commandline

path/to/src/withaspark.weather.cli.js --station=KJAX temperature
# 68

path/to/src/withaspark.weather.cli.js --station=KJAX sunrise
# "2019-04-28T06:47:22.419-04:00"

path/to/src/withaspark.weather.cli.js --station=KJAX
# { station: 'KJAX',
#   sunrise: '2019-04-28T06:47:22.419-04:00',
#   sunset: '2019-04-28T20:03:36.240-04:00',
#   timestamp: '2019-04-28T02:58:00+00:00',
#   raw: 'KJAX 280056Z 15007KT 10SM FEW250 20/11 A2999 RMK AO2 SLP156 T02000111 $',
#   coordinates: '30.5,-81.7',
#   elevation: 30,
#   text: 'Mostly Clear',
#   temperature: 68,
#   dewpoint: 52,
#   windDirection: 150,
#   windSpeed: 0,
#   pressure: 762,
#   visibility: 10,
#   precipitation: 0,
#   humidity: 57,
#   feelsLike: 32,
#   alerts: '',
#   sunIcon: \uf02e,
#   conditionIcon: \uf02e,
#   isDay: 0,
#   isNight: 1,
#   isSunrise: 0,
#   isSunset: 0 }

Options

OptionDefaultDescription
station"KJAX"Local weather station to find weather for. Choose nearest station from https://www.aviationweather.gov/docs/metar/stations.txt.
cache_dir"/tmp"Directory to write cache files too.
cache_prefix"withaspark.weather."Prefix for cache file names.
cache_lifetime5Number of minutes to cache results before refetching.
user_agent"@withaspark/weather User"User agent to use when making requests to weather API. If experiencing rate-limiting issues, set to something unique.
unknown"?"Symbol for unknown value.

Properties

PropertyMethodDescription
stationgetStation()Get the weather station data was requested for. E.g., "KJAX".
sunrisegetSunrise()Get the ISO-8601 formatted time of sunrise for the station. E.g., "2019-04-28T06:47:22.419-04:00".
sunsetgetSunset()Get the ISO-8601 formatted time of sunset for the station. E.g., "2019-04-28T20:03:36.240-04:00".
timestampgetTimestamp()Get the timestamp of when the weather data was last fetched. E.g., "2019-04-28T01:58:00+00:00".
rawgetRaw()Get the raw METAR data for the station.
coordinatesgetCoordinates()Get the approximate longitude and latitude for the station.
elevationgetElevation()Get the approximate elevation for the station, in feet.
textgetText()Get the brief textual description of current conditions at the station.
temperaturegetTemperature()Get the current temperature at the station, in Fahrenheit.
dewpointgetDewpoint()Get the current dewpoint temperature at the station, in Fahrenheit.
windDirectionGetWindDirection()Get the current wind direction at the station, in degrees.
windSpeedgetWindSpeed()Get the current wind speed at the station, in mph.
pressuregetPressure()Get the current barometric pressure at the station, in mmHg.
visibilitygetVisibility()Get the current ground-level visibility at the station, in miles.
precipitationgetPrecipitation()Get the amount of precipitation in the last hour at the station, in inches.
humiditygetHumidity()Get the current relative humidity at the station, in percent.
feelsLikegetFeelsLike()Get the current feels-like temperature at the station, in degrees Fahrenheit.
alertsgetAlerts()Get the current weather advisory types at the station. This will contain a newline delimited list of advisory types.
sunIcongetSunIcon()Get the unicode character that represents the sun position. To be used with the font Weather Icons by @erikflowers.
conditionIcongetConditionIcon()Get the unicode character that represents the weather conditions. If it is currently clear with no conditions of note, it will return an empty string. To be used with the font Weather Icons by @erikflowers.
isDaygetIsDay()Get if the sun is currently up at the station. Returns integer value (value of 1 means sun is up).
isNightgetIsNight()Get if the sun is currently down at the station. Returns integer value (value of 1 means sun is down).
isSunrisegetIsSunrise()Get if the sun is currently rising at the station. Returns integer value (value of 1 means the sun is rising).
isSunsetgetIsSunset()Get if the sun is currently setting at the station. Returns integer value (value of 1 means the sun is setting).
2.0.3

3 years ago

2.0.2

4 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago

0.0.1

5 years ago