diff options
author | M. Voerman <rekordc@gmail.com> | 2015-02-07 22:19:12 +0100 |
---|---|---|
committer | M. Voerman <rekordc@gmail.com> | 2015-02-07 22:19:12 +0100 |
commit | 93b4f48499d080aaeb7d407262fa2070d2b88a07 (patch) | |
tree | 3d26550d97682889361f5dfe0183e1edfb674907 /javascript/weather.js | |
parent | b996f3095f547c621b5a445e464a836757de69b5 (diff) | |
download | vdr-vipclient-93b4f48499d080aaeb7d407262fa2070d2b88a07.tar.gz vdr-vipclient-93b4f48499d080aaeb7d407262fa2070d2b88a07.tar.bz2 |
Expanded weather info
Diffstat (limited to 'javascript/weather.js')
-rw-r--r-- | javascript/weather.js | 118 |
1 files changed, 106 insertions, 12 deletions
diff --git a/javascript/weather.js b/javascript/weather.js index 5ff2953..d0c9c2c 100644 --- a/javascript/weather.js +++ b/javascript/weather.js @@ -1,19 +1,10 @@ -function WeatherInfo() { - -//weather -//http://www.latlong.net/ -// find long lan -// -// - -var lat=52.41; -var lon=6.61; +function WeatherInfo_current() { xmlhttp=new XMLHttpRequest(); - xmlhttp.open("GET","http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&mode=xml&units=metric&lang=nl",false); + xmlhttp.open("GET","http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&type=accurate&mode=xml&units=metric",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; - var htmltext = "<h1 class=mainmenu" + cssres[css_nr][Set_Res] + ">" + " Current Weather </h1><pre class=mainmenu" + cssres[css_nr][Set_Res] +">"; + htmltext = "<h1 class=mainmenu" + cssres[css_nr][Set_Res] + ">" + " Current Weather </h1><pre class=mainmenu" + cssres[css_nr][Set_Res] +">"; htmltext += " Plaats : " + xmlDoc.getElementsByTagName("city")[0].getAttribute("name") + ","; htmltext += xmlDoc.getElementsByTagName("country")[0].childNodes[0].nodeValue + "\n"; htmltext += " Temperatuur : " + Math.round(xmlDoc.getElementsByTagName("temperature")[0].getAttribute("value")*10)/10; @@ -31,3 +22,106 @@ var lon=6.61; mainmenu.innerHTML = htmltext; } + +function WeatherInfo() { + + var htmltext = "<h1 class=mainmenu" + cssres[css_nr][Set_Res] + "> Weather Forecast </h1>"; + htmltext += "\n\n" + + xmlhttp=new XMLHttpRequest(); + xmlhttp.open('GET','http://api.openweathermap.org/data/2.5/forecast/daily?q=' + city + '&type=accurate&mode=xml&units=metric&cnt=7',false); + xmlhttp.send(); + xmlDoc=xmlhttp.responseXML; + try { + var x=xmlDoc.getElementsByTagName("time"); + + htmltext += "<table class='center weather" + cssres[css_nr][Set_Res] + "'><tr>"; + +var date = new Date(); +var y = date.getDay(); + for (var i=0;i<x.length;i++) { + htmltext += "<th>" + days[y] + "</th>"; + y++;if (y > 6) {y = 0} ; + } + htmltext += "</tr>"; + + htmltext += "<tr>"; + + for (var i=0;i<x.length;i++) { + htmltext += "<th>" + x[i].getAttribute('day') + "</th>"; + } + htmltext += "</tr>"; + + htmltext += "<tr>"; + for (var i=0;i<x.length;i++) { + htmltext += "<th><img class='imgsize" + cssres[css_nr][Set_Res] + "' src='http://openweathermap.org/img/w/" + x[i].getElementsByTagName("symbol")[0].getAttribute('var') + ".png' /></th>"; + } + htmltext += "</tr>"; + + htmltext += "<tr>"; + for (var i=0;i<x.length;i++) { + htmltext += "<th> Day: " + x[i].getElementsByTagName("temperature")[0].getAttribute('day') + "</th>"; + } + htmltext += "</tr>"; + + htmltext += "<tr>"; + for (var i=0;i<x.length;i++) { + htmltext += "<th> Night: " + x[i].getElementsByTagName("temperature")[0].getAttribute('night') + "</th>"; + } + htmltext += "</tr>"; + + htmltext += "<tr>"; + for (var i=0;i<x.length;i++) { + htmltext += "<th>"; + if (x[i].getElementsByTagName("precipitation")[0].getAttribute('value')) { + htmltext += x[i].getElementsByTagName("precipitation")[0].getAttribute('value'); + htmltext += " mm " + x[i].getElementsByTagName("precipitation")[0].getAttribute('type') + "</th>"; + } + htmltext += "</th>"; + } + htmltext += "</tr>"; + + htmltext += "<tr>"; + for (var i=0;i<x.length;i++) { + htmltext += "<th> Wind: " + x[i].getElementsByTagName("windDirection")[0].getAttribute('code'); + htmltext += "<br> " + x[i].getElementsByTagName("windSpeed")[0].getAttribute('mps') + " m/s </th>"; + } + htmltext += "</tr>"; + + htmltext += "</table><br><br>"; + + var x=xmlDoc.getElementsByTagName("location"); + htmltext += "<table class='center weather" + cssres[css_nr][Set_Res] + "'><tr>"; + htmltext += "<th>"; + htmltext += "Location"; + htmltext += "</th><th> : "; + htmltext += x[0].getElementsByTagName("name")[0].childNodes[0].nodeValue; + htmltext += "," + x[0].getElementsByTagName("country")[0].childNodes[0].nodeValue; + htmltext += "</th></tr><tr><th>"; + htmltext += "latitude"; + htmltext += "</th><th> : "; + htmltext += x[0].getElementsByTagName("location")[0].getAttribute('latitude'); + htmltext += "</th></tr><tr><th>"; + htmltext += "longitude"; + htmltext += "</th><th> : "; + htmltext += x[0].getElementsByTagName("location")[0].getAttribute('longitude'); + htmltext += "</th></tr><tr><th>"; + htmltext += "Sun rise"; + htmltext += "</th><th> : "; + htmltext += Right(xmlDoc.getElementsByTagName("sun")[0].getAttribute('rise'),8); + htmltext += "</th></tr><tr><th>"; + htmltext += "Sun set"; + htmltext += "</th><th> : "; + htmltext += Right(xmlDoc.getElementsByTagName("sun")[0].getAttribute('set'),8); + htmltext += "</th></tr></table>"; + + } catch(e) { + htmltext = "<h1 class=mainmenu" + cssres[css_nr][Set_Res] + "><pre>\n\n\n" + Lang[67] + "\n\n\n</pre></h1>"; + alert(e); + } + + mainmenu.innerHTML = htmltext; + +} + + |