Last active
April 23, 2016 06:58
-
-
Save ki11ua/9483d67211faa2c275da54f02ed24284 to your computer and use it in GitHub Desktop.
Super Simple JQuery Weather Widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.weatherfeed{ | |
color: rgba( 255, 255, 255, 1); | |
text-align: right; | |
font-size: 16px; | |
max-width:350px; | |
line-height: 1.43em; | |
background-position: 25% -50%; | |
background-repeat: no-repeat; | |
} | |
.weatherfeed .title{ | |
font-size: 18px; | |
font-weight: 700; | |
} | |
.weatherfeed .temp { | |
font-size: 3em; | |
line-height: 1.25em; | |
color: rgba(40, 40, 40, 1); | |
} | |
.weatherfeed strong { | |
font-weight: 700; | |
color: rgba( 255, 255, 255, 1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="weather"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getWeather() { | |
var location ='Zakynthos, GR'; | |
var compass = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N']; | |
$.ajax({ | |
dataType: "json", | |
headers: { "Accept": "application/json; odata=verbose" }, | |
url: "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%27"+location+"%27%20limit%201&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys", | |
beforeSend: function(xhr){xhr.setRequestHeader('Accept', 'application/json; odata=verbose');}, | |
success: function(data){ | |
$.getJSON("https://query.yahooapis.com/v1/public/yql?callback=?", { | |
q: "select * from weather.forecast where woeid="+data.query.results.place.locality1.woeid+" and u='c'", | |
format: "json" | |
},function (data) { | |
var weather = data.query.results.rss.channel; | |
console.log(weather); | |
var image = 'https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/' + weather.item.condition.code + 'd.png'; | |
var html = '<div class="weatherfeed" style="background-image:url('+image+')"><div class="title">Weather now in '+weather.location.city+'</div><div class="temp">'+weather.item.condition.temp+'°'+weather.units.temperature+'</div><div class="currently"><strong>Condition:</strong> '+weather.item.condition.text+'</div><div class="currently"><strong>Humidity:</strong> '+weather.atmosphere.humidity+'%</div><div><strong>Wind:</strong> '+compass[Math.round(weather.wind.direction / 22.5)]+' '+weather.wind.speed+' '+weather.units.speed+'</div></div>'; | |
$("#weather").html(html); | |
}); | |
}, | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment