Weather Icon
by Ben Clayton
HTML
<object type="image/svg+xml" class="weather icon" data="" width=150 height=150>
Your browser does not support SVG
</object>
<br/>
<div class="weather temp"></div>
CSS
.weather.temp {
font-size: 36px;
}
JavaScript
function getw() {
$.ajax({
url: "https://api.weather.com/v1/location/TN34:4:GB/observations/current.json",
data: {
"units": "m",
"apiKey": "6c093640e273a52369b2cb05ea9cd55b"
},
crossDomain: true,
dataType: 'json',
method: 'GET',
cache: true
})
.done(function(data) {
var windex = data.observation.icon_code;
$(".weather.icon").attr("data", "https://staging-vending.lrsdedicated.com/dyn/_pictures/weather-icons/" + windex + ".svg");
$(".weather.temp").html(data.observation.metric.temp + "°C")
if (console && console.log) {
console.log(data);
}
console.log("expire: ", data.metadata.expire_time_gmt * 1000);
console.log("now: ", (new Date()).getTime());
var t1 = data.metadata.expire_time_gmt * 1000;
var t2 = (new Date()).getTime();
console.log("minutes to next update",(t1 - t2) / (1000 * 60));
});
};
$(document).ready(function() {
getw();
setInterval(getw, 5000);
});