Skip to content
Snippets Groups Projects
Commit 6997cc23 authored by Kasalehlia's avatar Kasalehlia
Browse files

hardened weather module and added attribution to wunderground

parent f71541de
No related branches found
Tags v2020.2.2.1-ffbs-next
No related merge requests found
......@@ -24,33 +24,38 @@ function fetchCurrent (cityid, cb) {
var url = "http://api.openweathermap.org/data/2.5/weather?units=metric&id="+cityid+"&appid="+APPID;
httpreq.get(url, function (err, res) {
var dat = JSON.parse(res.body);
cb({
temp: dat.main.temp,
wind: {speed: dat.wind.speed, dir: degToDirection(dat.wind.deg)},
pressure: dat.main.pressure,
humidity: dat.main.humidity,
main: dat.weather[0].main,
desc: dat.weather[0].description,
icon: iconBaseURL+dat.weather[0].icon+'.png'
});
if (dat.cod) {
cb({
temp: dat.main.temp,
wind: {speed: dat.wind.speed, dir: degToDirection(dat.wind.deg)},
pressure: dat.main.pressure,
humidity: dat.main.humidity,
main: dat.weather[0].main,
desc: dat.weather[0].description,
icon: iconBaseURL+dat.weather[0].icon+'.png'
});
}
});
}
function fetchForecast (cityid, count, cb) {
var url = "http://api.openweathermap.org/data/2.5/forecast?units=metric&id="+cityid+"&appid="+APPID;
httpreq.get(url, function (err, res) {
var dat = JSON.parse(res.body).list.slice(0,count);
cb(dat.map(function (d) {
var date = new Date(d.dt*1000);
return {
time: pad(date.getHours(),2)+':'+pad(date.getMinutes(),2),
temp: d.main.temp,
wind: {speed: d.wind.speed, dir: degToDirection(d.wind.deg)},
main: d.weather[0].main,
desc: d.weather[0].description,
icon: iconBaseURL+d.weather[0].icon+'.png'
}
}));
var raw = JSON.parse(res.body);
if (raw.list) {
var dat = raw.list.slice(0,count);
cb(dat.map(function (d) {
var date = new Date(d.dt*1000);
return {
time: pad(date.getHours(),2)+':'+pad(date.getMinutes(),2),
temp: d.main.temp,
wind: {speed: d.wind.speed, dir: degToDirection(d.wind.deg)},
main: d.weather[0].main,
desc: d.weather[0].description,
icon: iconBaseURL+d.weather[0].icon+'.png'
}
}));
}
});
}
......
<h3>Current Weather</h3>
<h3>Current Weather <img src="/modules/weather/wundergroundLogo_4c_rev_horz.png"></img></h3>
<div style="width: 200px">
<img src="{{current.icon}}" align="left">
<b>{{current.main}}</b><br>{{current.desc}}
......
......@@ -59,6 +59,11 @@ h3 {
#weather th {
text-align: left;
}
#weather h3 img {
height: 1em;
float: right;
margin-right: 0.5em;
}
#calendar {
font-size: 120%;
}
......
public/modules/weather/wundergroundLogo_4c_rev_horz.png

22.8 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment