Skip to content
This repository has been archived by the owner on Jan 23, 2019. It is now read-only.

Commit

Permalink
Added WOEID to simpleWeather, version now 2.1.0, and updated included…
Browse files Browse the repository at this point in the history
… demo.
  • Loading branch information
fleeting committed Nov 18, 2012
1 parent e550019 commit 6b002f0
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 107 deletions.
181 changes: 113 additions & 68 deletions index.html

Large diffs are not rendered by default.

13 changes: 0 additions & 13 deletions jquery.simpleWeather-2.0.1.min.js

This file was deleted.

13 changes: 13 additions & 0 deletions jquery.simpleWeather-2.1.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 25 additions & 22 deletions jquery.simpleWeather.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
/*
* simpleWeather
*
* A simple jQuery plugin to display the weather information
* for a location. Weather is pulled from the public Yahoo!
* Weather feed via their api.
* simpleWeather.js
* http://simpleweather.monkeecreate.com
*
* Developed by James Fleeting <hello@jamesfleeting.com>
* A simple jQuery plugin to display the current weather
* information for any location using Yahoo! Weather.
*
* Developed by James Fleeting <@twofivethreetwo>
* Another project from monkeeCreate <http://monkeecreate.com>
*
* Version 2.0.1 - Last updated: January 26 2012
* Version 2.1 - Last updated: November 17 2012
*/
(function($) {
"use strict";
$.extend({
simpleWeather: function(options){
options = $.extend({
zipcode: '76309',
zipcode: '',
woeid: '2357536',
location: '',
unit: 'f',
success: function(weather){},
error: function(message){}
}, options);

var now = new Date();

var weatherUrl = 'http://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 location in (select id from weather.search where query="'+options.location+'") and u="'+options.unit+'"';
} else if(options.zipcode !== '') {
weatherUrl += 'select * from weather.forecast where location in ("'+options.zipcode+'") and u="'+options.unit+'"';
} else if(options.woeid !== '') {
weatherUrl += 'select * from weather.forecast where woeid='+options.woeid+' and u="'+options.unit+'"';
} else {
options.error("No location given.");
options.error("No location given. Please provide either a US zip code, WOEID or location.");
return false;
}

$.getJSON(
weatherUrl,
function(data) {
Expand All @@ -42,33 +45,33 @@
if (result.constructor.toString().indexOf("Array") !== -1) {
result = result[0];
}

var currentDate = new Date();
var sunRise = new Date(currentDate.toDateString() +' '+ result.astronomy.sunrise);
var sunSet = new Date(currentDate.toDateString() +' '+ result.astronomy.sunset);

if(currentDate>sunRise && currentDate<sunSet) {
var timeOfDay = 'd';
var timeOfDay = 'd';
} else {
var timeOfDay = 'n';
}

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));
} else {
var heatIndex = result.item.condition.temp;
}

if(options.unit === "f") {
var tempAlt = Math.round((5.0/9.0)*(result.item.condition.temp-32.0));
} else {
var tempAlt = Math.round((9.0/5.0)*result.item.condition.temp+32.0);
}
var weather = {

var weather = {
title: result.item.title,
temp: result.item.condition.temp,
tempAlt: tempAlt,
Expand Down Expand Up @@ -114,7 +117,7 @@
updated: result.item.pubDate,
link: result.item.link
};

options.success(weather);
});
} else {
Expand All @@ -127,6 +130,6 @@
}
);
return this;
}
}
});
})(jQuery);
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "simpleweather",
"version": "2.0.1",
"title": "simpleWeather",
"name": "simpleweather.js",
"version": "2.1",
"title": "simpleWeather.js",
"author": {
"name": "James Fleeting",
"email": "hello@jamesfleeting.com",
Expand All @@ -16,7 +16,7 @@
"dependencies": {
"jquery": ">1.5"
},
"description": "A simple jQuery plugin to display the weather information for any location. The data is pulled from the public Yahoo! Weather feed via the YQL API.",
"description": "A simple jQuery plugin to display the current weather information for any location using Yahoo! Weather. Developed by James Fleeting.",
"keywords": [
"weather",
"yahoo",
Expand Down

0 comments on commit 6b002f0

Please sign in to comment.