jw-weather
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -8,2 +8,3 @@ var Weather = require('./weather'); | ||
var DarkSky_Key = '0123456789abcdef9876543210fedcba'; //this is a fake key | ||
var boston = new Weather.service({ | ||
@@ -21,3 +22,3 @@ provider: 'darksky', | ||
} else { | ||
console.log('\r\n---Boston Weather---'); | ||
console.log('\r\n---Boston Weather (DarkSky)---'); | ||
printWeather(boston); | ||
@@ -41,2 +42,3 @@ } | ||
var AccuWeather_Key = '0123456789abcdef9876543210fedcba'; //this is a fake key | ||
var AccuWeather_Houston; //create a reference outside the callback | ||
@@ -66,3 +68,3 @@ | ||
} else { | ||
console.log('---Houston Weather---'); | ||
console.log('---Houston Weather (AccuWeather)---'); | ||
printWeather(AccuWeather_Houston); | ||
@@ -69,0 +71,0 @@ } |
{ | ||
"name": "jw-weather", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Reader for various weather APIs", | ||
@@ -14,3 +14,3 @@ "main": "weather.js", | ||
"keywords": [ | ||
"weather", "DarkSky","AccuWeather" | ||
"Weather", "DarkSky","AccuWeather","Forecast" | ||
], | ||
@@ -17,0 +17,0 @@ "author": "Jonathan Wyett", |
@@ -33,3 +33,3 @@ # jw-weather | ||
- lastUpdate (When the update was run locally) | ||
- forecastTime (The actual forecast time for the the provider) | ||
- forecastTime (The actual forecast time from the the provider) | ||
- temp | ||
@@ -39,4 +39,6 @@ - feelsLike | ||
- currentCondition | ||
- An icon name/number | ||
- sunrise (DarkSky only) | ||
- sunset (DarkSky only) | ||
- A 5-day forecast (DarkSky only) | ||
@@ -43,0 +45,0 @@ When using AccuWeather there is a helper function for looking up location keys since AccuWeather does not use latitude/longitude in it's API call. |
20
test.js
@@ -55,3 +55,3 @@ function formatDate(fullDate, formatString) { | ||
var Weather = require('./weather'); | ||
/* | ||
var darksky = new Weather.service({ | ||
@@ -88,2 +88,6 @@ provider: 'darksky', | ||
console.log('Sunset: ' + formatTime(darksky.sunset, 'short')); | ||
console.log('icon: ' + darksky.icon); | ||
console.log('daily: '); | ||
console.log('5-Day Forecast:'); | ||
console.log(JSON.stringify(darksky.forecast)); | ||
} | ||
@@ -93,3 +97,8 @@ | ||
*/ | ||
/* | ||
var accuweather = null; | ||
@@ -145,6 +154,9 @@ | ||
//console.log('Sunrise: ' + formatTime(weather.sunrise, 'short')); | ||
//console.log('Sunset: ' + formatTime(weather.sunset, 'short')); | ||
//console.log('Sunset: ' + formatTime(weather.sunset, 'short')); | ||
console.log('icon: ' + accuweather.icon) ; | ||
console.log(JSON.stringify(accuweather.raw)); | ||
} | ||
}); | ||
} | ||
*/ |
@@ -12,6 +12,6 @@ /* | ||
* @param {'darksky'|'accuweather'} options.provider - The weather provider to use | ||
* @param {Number} options.latitude - The latitude (Darksky) | ||
* @param {Number} options.longitude - the longitude (Darksky) | ||
* @param {String} options.locationKey - the location key (Accuweather) | ||
* @param {boolean} options.celsius - Temperature in celsius | ||
* @param {Number} [options.latitude] - The latitude (Darksky) | ||
* @param {Number} [options.longitude] - the longitude (Darksky) | ||
* @param {String} [options.locationKey] - the location key (Accuweather) | ||
* @param {boolean} [options.celsius] - Temperature in celsius | ||
* | ||
@@ -30,2 +30,3 @@ * @param {Function} [callback] | ||
this.currentCondition = null; | ||
this.icon = null; | ||
this.feelsLike = null; | ||
@@ -35,2 +36,3 @@ this.sunrise = null; | ||
this.error = null; | ||
this.forecast = []; | ||
@@ -105,3 +107,5 @@ (function startup() { | ||
sunset: _self.sunset, | ||
forecastTime: _self.forecastTime | ||
forecastTime: _self.forecastTime, | ||
forecast: _self.forecast, | ||
icon: _self.icon | ||
}; | ||
@@ -130,10 +134,30 @@ | ||
_self.sunset = new Date(weather.daily.data[0].sunsetTime * 1000); | ||
_self.icon = weather.currently.icon; | ||
//set celsius if desired | ||
if (options.celsius) { | ||
_self.temp = (_self.temp-32)*(5/9); | ||
_self.temp = _self.temp.toFixed(2); //round to 2 decimal places | ||
_self.temp = toCelsius(_self.temp); | ||
_self.feelsLike = toCelsius(_self.feelsLike); | ||
} | ||
_self.feelsLike = (_self.feelsLike-32)*(5/9); | ||
_self.feelsLike = _self.feelsLike.toFixed(2); | ||
//create the forecast | ||
for (var i=0; i<5; i++) { | ||
var day = getDailyObject(); | ||
day.condition = weather.daily.data[i].summary; | ||
day.feelsLikeHigh = weather.daily.data[i].apparentTemperatureHigh.toFixed(2); | ||
day.feelsLikeLow = weather.daily.data[i].apparentTemperatureLow.toFixed(2); | ||
day.humidity = weather.daily.data[i].humidity; | ||
day.icon = weather.daily.data[i].icon; | ||
day.sunrise = new Date(weather.daily.data[i].sunriseTime * 1000); | ||
day.sunset = new Date(weather.daily.data[i].sunsetTime * 1000); | ||
day.tempHigh = weather.daily.data[i].temperatureHigh.toFixed(2); | ||
day.tempLow = weather.daily.data[i].temperatureLow.toFixed(2); | ||
if (options.celsius) { | ||
day.feelsLikeHigh = toCelsius(day.feelsLikeHigh); | ||
day.feelsLikeLow = toCelsius(day.feelsLikeLow); | ||
day.tempHigh = toCelsius(day.tempHigh); | ||
day.tempLow = toCelsius(day.tempLow); | ||
} | ||
_self.forecast.push(day); | ||
} | ||
@@ -164,10 +188,8 @@ | ||
_self.sunset = null; | ||
_self.icon = weather.WeatherIcon; | ||
//set celsius if desired | ||
if (options.celsius) { | ||
_self.temp = (_self.temp-32)*(5/9); | ||
_self.temp = _self.temp.toFixed(2); //round to 2 decimal places | ||
_self.feelsLike = (_self.feelsLike-32)*(5/9); | ||
_self.feelsLike = _self.feelsLike.toFixed(2); | ||
_self.temp = toCelsius(_self.temp); | ||
_self.feelsLike = toCelsius(_self.feelsLike); | ||
} | ||
@@ -190,6 +212,5 @@ | ||
* @param {String} options.key - API Key | ||
* @param {number} options.latitude - The latitude | ||
* @param {number} options.longitude - the longitude | ||
* @param {string} options.zipcode - the zipcode | ||
* @param {boolean} options.celsius - Temperature in celsius | ||
* @param {number|string} [options.latitude] - The latitude | ||
* @param {number|string} [options.longitude] - the longitude | ||
* @param {number|string} [options.zipcode] - the zipcode | ||
* @param {function} callback | ||
@@ -252,3 +273,23 @@ */ | ||
function toCelsius(temp) { | ||
return ((temp-32)*(5/9)).toFixed(2); | ||
} | ||
function getDailyObject() { | ||
var daily = { | ||
tempHigh: null, | ||
tempLow: null, | ||
humidity: null, | ||
condition: null, | ||
feelsLikeHigh: null, | ||
feelsLikeLow: null, | ||
sunrise: null, | ||
sunset: null, | ||
icon: null | ||
}; | ||
return daily; | ||
} | ||
exports.service = service; | ||
exports.accuweatherLocationLookup = accuweatherLocationLookup; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
95272
11
2123
46
3