Skip to content

Commit

Permalink
Added gulp for a build process and speed up pushing out a release. Au…
Browse files Browse the repository at this point in the history
…tomate ALL THE THINGS. Also some code cleanup and bug fixes.

Fix for 3200 (not available) condition code and related image [monkeecreate#77].

Fixed my assumption of query being present [monkeecreate#72].
  • Loading branch information
fleeting committed Apr 17, 2014
1 parent 36f0f22 commit 3c004e7
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 61 deletions.
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
13 changes: 11 additions & 2 deletions component.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@
"description": "A simple jQuery plugin to display current weather data for any location and doesn't get in your way.",
"version": "2.6.0",
"main": "jquery.simpleWeather.js",
"scripts": ["jquery.simpleWeather.js"],
"scripts": [
"jquery.simpleWeather.js"
],
"dependencies": {
"components/jquery": "*"
},
"author": "James Fleeting",
"keywords": ["jquery", "javascript", "weather", "plugin", "simple", "monkeecreate"],
"keywords": [
"jquery",
"javascript",
"weather",
"plugin",
"simple",
"monkeecreate"
],
"license": "MIT",
"demo": "http://simpleweatherjs.com"
}
41 changes: 41 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var gulp = require('gulp'),
uglify = require('gulp-uglify'),
jshint = require('gulp-jshint'),
rename = require('gulp-rename'),
bump = require('gulp-bump'),
notify = require('gulp-notify'),
git = require('gulp-git'),
size = require('gulp-size'),
pkg = require('./package.json');

var source = "jquery.simpleWeather.js",
sourceMin = "jquery.simpleWeather.min.js";

gulp.task('lint', function () {
return gulp.src(source)
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'));
});


gulp.task('build', ['lint'], function () {
return gulp.src(source)
.pipe(rename(sourceMin))
.pipe(uglify({preserveComments: 'all'}))
.pipe(size())
.pipe(gulp.dest('./'));
});

gulp.task('bump', function () {
return gulp.src(['./bower.json', './component.json', 'simpleweather.jquery.json'])
.pipe(bump({version: pkg.version}))
.pipe(gulp.dest('./'));
});

gulp.task('tag', ['bump'], function () {
return gulp.src('./')
.pipe(git.commit('Version '+pkg.version))
.pipe(git.tag(pkg.version, 'Version '+pkg.version))
.pipe(git.push('monkee', 'master', '--tags'))
.pipe(gulp.dest('./'));
});
132 changes: 78 additions & 54 deletions jquery.simpleWeather.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Developed by James Fleeting <@fleetingftw> <http://iwasasuperhero.com>
* Another project from monkeeCreate <http://monkeecreate.com>
*
* Version 2.6.0 - Last updated: February 26 2014
* Version 2.7.0 - Last updated: April 17 2014
*/
(function($) {
"use strict";
Expand All @@ -23,7 +23,6 @@
}, options);

var now = new Date();

var weatherUrl = '//query.yahooapis.com/v1/public/yql?format=json&rnd='+now.getFullYear()+now.getMonth()+now.getDay()+now.getHours()+'&diagnostics=true&callback=?&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q=';
if(options.location !== '') {
weatherUrl += 'select * from weather.forecast where woeid in (select woeid from geo.placefinder where text="'+options.location+'" and gflags="R") and u="'+options.unit+'"';
Expand All @@ -37,71 +36,96 @@
$.getJSON(
encodeURI(weatherUrl),
function(data) {
if(data !== null && data.query.results !== null && data.query.results.channel.description !== 'Yahoo! Weather Error') {
if(data !== null && data.query !== null && data.query.results !== null && data.query.results.channel.description !== 'Yahoo! Weather Error') {
$.each(data.query.results, function(i, result) {
if (result.constructor.toString().indexOf("Array") !== -1) {
result = result[0];
}

var altTemps = [], heatIndex, images = [];
var compass = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N'];
var windDirection = compass[Math.round(result.wind.direction / 22.5)];

if(result.item.condition.temp < 80 && result.atmosphere.humidity < 40) {
var heatIndex = -42.379+2.04901523*result.item.condition.temp+10.14333127*result.atmosphere.humidity-0.22475541*result.item.condition.temp*result.atmosphere.humidity-6.83783*(Math.pow(10, -3))*(Math.pow(result.item.condition.temp, 2))-5.481717*(Math.pow(10, -2))*(Math.pow(result.atmosphere.humidity, 2))+1.22874*(Math.pow(10, -3))*(Math.pow(result.item.condition.temp, 2))*result.atmosphere.humidity+8.5282*(Math.pow(10, -4))*result.item.condition.temp*(Math.pow(result.atmosphere.humidity, 2))-1.99*(Math.pow(10, -6))*(Math.pow(result.item.condition.temp, 2))*(Math.pow(result.atmosphere.humidity,2));
heatIndex = -42.379+2.04901523*result.item.condition.temp+10.14333127*result.atmosphere.humidity-0.22475541*result.item.condition.temp*result.atmosphere.humidity-6.83783*(Math.pow(10, -3))*(Math.pow(result.item.condition.temp, 2))-5.481717*(Math.pow(10, -2))*(Math.pow(result.atmosphere.humidity, 2))+1.22874*(Math.pow(10, -3))*(Math.pow(result.item.condition.temp, 2))*result.atmosphere.humidity+8.5282*(Math.pow(10, -4))*result.item.condition.temp*(Math.pow(result.atmosphere.humidity, 2))-1.99*(Math.pow(10, -6))*(Math.pow(result.item.condition.temp, 2))*(Math.pow(result.atmosphere.humidity,2));
} else {
var heatIndex = result.item.condition.temp;
heatIndex = result.item.condition.temp;
}

if(options.unit === "f") {
var unitAlt = "c";
var tempAlt = Math.round((5.0/9.0)*(result.item.condition.temp-32.0));
var highAlt = Math.round((5.0/9.0)*(result.item.forecast[0].high-32.0));
var lowAlt = Math.round((5.0/9.0)*(result.item.forecast[0].low-32.0));
var tomorrowHighAlt = Math.round((5.0/9.0)*(result.item.forecast[1].high-32.0));
var tomorrowLowAlt = Math.round((5.0/9.0)*(result.item.forecast[1].low-32.0));
var forecastOneHighAlt = Math.round((5.0/9.0)*(result.item.forecast[1].high-32.0));
var forecastOneLowAlt = Math.round((5.0/9.0)*(result.item.forecast[1].low-32.0));
var forecastTwoHighAlt = Math.round((5.0/9.0)*(result.item.forecast[2].high-32.0));
var forecastTwoLowAlt = Math.round((5.0/9.0)*(result.item.forecast[2].low-32.0));
var forecastThreeHighAlt = Math.round((5.0/9.0)*(result.item.forecast[3].high-32.0));
var forecastThreeLowAlt = Math.round((5.0/9.0)*(result.item.forecast[3].low-32.0));
var forecastFourHighAlt = Math.round((5.0/9.0)*(result.item.forecast[4].high-32.0));
var forecastFourLowAlt = Math.round((5.0/9.0)*(result.item.forecast[4].low-32.0));
altTemps.unit = "c";
altTemps.temp = Math.round((5.0/9.0)*(result.item.condition.temp-32.0));
altTemps.high = Math.round((5.0/9.0)*(result.item.forecast[0].high-32.0));
altTemps.low = Math.round((5.0/9.0)*(result.item.forecast[0].low-32.0));
altTemps.forecastOneHigh = Math.round((5.0/9.0)*(result.item.forecast[1].high-32.0));
altTemps.forecastOneLow = Math.round((5.0/9.0)*(result.item.forecast[1].low-32.0));
altTemps.forecastTwoHigh = Math.round((5.0/9.0)*(result.item.forecast[2].high-32.0));
altTemps.forecastTwoLow = Math.round((5.0/9.0)*(result.item.forecast[2].low-32.0));
altTemps.forecastThreeHigh = Math.round((5.0/9.0)*(result.item.forecast[3].high-32.0));
altTemps.forecastThreeLow = Math.round((5.0/9.0)*(result.item.forecast[3].low-32.0));
altTemps.forecastFourHigh = Math.round((5.0/9.0)*(result.item.forecast[4].high-32.0));
altTemps.forecastFourLow = Math.round((5.0/9.0)*(result.item.forecast[4].low-32.0));
} else {
altTemps.unit = "f";
altTemps.temp = Math.round((9.0/5.0)*result.item.condition.temp+32.0);
altTemps.high = Math.round((9.0/5.0)*result.item.forecast[0].high+32.0);
altTemps.low = Math.round((9.0/5.0)*result.item.forecast[0].low+32.0);
altTemps.forecastOneHigh = Math.round((9.0/5.0)*(result.item.forecast[1].high+32.0));
altTemps.forecastOneLow = Math.round((9.0/5.0)*(result.item.forecast[1].low+32.0));
altTemps.forecastTwoHigh = Math.round((9.0/5.0)*(result.item.forecast[2].high+32.0));
altTemps.forecastTwoLow = Math.round((9.0/5.0)*(result.item.forecast[2].low+32.0));
altTemps.forecastThreeHigh = Math.round((9.0/5.0)*(result.item.forecast[3].high+32.0));
altTemps.forecastThreeLow = Math.round((9.0/5.0)*(result.item.forecast[3].low+32.0));
altTemps.forecastFourHigh = Math.round((9.0/5.0)*(result.item.forecast[4].high+32.0));
altTemps.forecastFourLow = Math.round((9.0/5.0)*(result.item.forecast[4].low+32.0));
}

if(result.item.condition.code == "3200") {
images.thumbnail = "//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png";
images.image = "//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png";
} else {
var unitAlt = "f";
var tempAlt = Math.round((9.0/5.0)*result.item.condition.temp+32.0);
var highAlt = Math.round((9.0/5.0)*result.item.forecast[0].high+32.0);
var lowAlt = Math.round((9.0/5.0)*result.item.forecast[0].low+32.0);
var tomorrowHighAlt = Math.round((9.0/5.0)*(result.item.forecast[1].high+32.0));
var tomorrowLowAlt = Math.round((9.0/5.0)*(result.item.forecast[1].low+32.0));
var forecastOneHighAlt = Math.round((9.0/5.0)*(result.item.forecast[1].high+32.0));
var forecastOneLowAlt = Math.round((9.0/5.0)*(result.item.forecast[1].low+32.0));
var forecastTwoHighAlt = Math.round((9.0/5.0)*(result.item.forecast[2].high+32.0));
var forecastTwoLowAlt = Math.round((9.0/5.0)*(result.item.forecast[2].low+32.0));
var forecastThreeHighAlt = Math.round((9.0/5.0)*(result.item.forecast[3].high+32.0));
var forecastThreeLowAlt = Math.round((9.0/5.0)*(result.item.forecast[3].low+32.0));
var forecastFourHighAlt = Math.round((9.0/5.0)*(result.item.forecast[4].high+32.0));
var forecastFourLowAlt = Math.round((9.0/5.0)*(result.item.forecast[4].low+32.0));
images.thumbnail = "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.condition.code+"ds.png";
images.image = "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.condition.code+"d.png";
}

if(result.item.forecast[1].code == "3200")
images.forecastOne = "//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png";
else
images.forecastOne = "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[1].code+"d.png";

if(result.item.forecast[2].code == "3200")
images.forecastTwo = "//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png";
else
images.forecastTwo = "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[2].code+"d.png";

if(result.item.forecast[3].code == "3200")
images.forecastThree = "//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png";
else
images.forecastThree = "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[3].code+"d.png";

if(result.item.forecast[4].code == "3200")
images.forecastFour = "//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png";
else
images.forecastFour = "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[4].code+"d.png";

var weather = {
title: result.item.title,
temp: result.item.condition.temp,
tempAlt: tempAlt,
tempAlt: altTemps.temp,
code: result.item.condition.code,
todayCode: result.item.forecast[0].code,
units:{
temp: result.units.temperature,
distance: result.units.distance,
pressure: result.units.pressure,
speed: result.units.speed,
tempAlt: unitAlt
tempAlt: altTemps.unit
},
currently: result.item.condition.text,
high: result.item.forecast[0].high,
highAlt: highAlt,
highAlt: altTemps.high,
low: result.item.forecast[0].low,
lowAlt: lowAlt,
lowAlt: altTemps.low,
forecast: result.item.forecast[0].text,
wind:{
chill: result.wind.chill,
Expand All @@ -116,63 +140,63 @@
sunrise: result.astronomy.sunrise,
sunset: result.astronomy.sunset,
description: result.item.description,
thumbnail: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.condition.code+"ds.png",
image: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.condition.code+"d.png",
thumbnail: images.thumbnail,
image: images.image,
tomorrow:{
high: result.item.forecast[1].high,
highAlt: tomorrowHighAlt,
highAlt: altTemps.forecastOneHigh,
low: result.item.forecast[1].low,
lowAlt: tomorrowLowAlt,
lowAlt: altTemps.forecastOneLow,
forecast: result.item.forecast[1].text,
code: result.item.forecast[1].code,
date: result.item.forecast[1].date,
day: result.item.forecast[1].day,
image: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[1].code+"d.png"
image: images.forecastOne
},
forecasts:{
one:{
high: result.item.forecast[1].high,
highAlt: forecastOneHighAlt,
highAlt: altTemps.forecastOneHigh,
low: result.item.forecast[1].low,
lowAlt: forecastOneLowAlt,
lowAlt: altTemps.forecastOneLow,
forecast: result.item.forecast[1].text,
code: result.item.forecast[1].code,
date: result.item.forecast[1].date,
day: result.item.forecast[1].day,
image: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[1].code+"d.png"
image: images.forecastOne
},
two:{
high: result.item.forecast[2].high,
highAlt: forecastTwoHighAlt,
highAlt: altTemps.forecastTwoHigh,
low: result.item.forecast[2].low,
lowAlt: forecastTwoLowAlt,
lowAlt: altTemps.forecastTwoLow,
forecast: result.item.forecast[2].text,
code: result.item.forecast[2].code,
date: result.item.forecast[2].date,
day: result.item.forecast[2].day,
image: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[2].code+"d.png"
image: images.forecastTwo
},
three:{
high: result.item.forecast[3].high,
highAlt: forecastThreeHighAlt,
highAlt: altTemps.forecastThreeHigh,
low: result.item.forecast[3].low,
lowAlt: forecastThreeLowAlt,
lowAlt: altTemps.forecastThreeLow,
forecast: result.item.forecast[3].text,
code: result.item.forecast[3].code,
date: result.item.forecast[3].date,
day: result.item.forecast[3].day,
image: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[3].code+"d.png"
image: images.forecastThree
},
four:{
high: result.item.forecast[4].high,
highAlt: forecastFourHighAlt,
highAlt: altTemps.forecastFourHigh,
low: result.item.forecast[4].low,
lowAlt: forecastFourLowAlt,
lowAlt: altTemps.forecastFourLow,
forecast: result.item.forecast[4].text,
code: result.item.forecast[4].code,
date: result.item.forecast[4].date,
day: result.item.forecast[4].day,
image: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[4].code+"d.png"
image: images.forecastFour
},
},
city: result.location.city,
Expand Down
Loading

0 comments on commit 3c004e7

Please sign in to comment.