screen/js/level2.js

342 lines
9.1 KiB
JavaScript
Raw Normal View History

2014-08-31 04:00:35 +02:00
! function($) {
2014-08-31 04:00:35 +02:00
$(function() {
refreshTime();
2014-08-31 04:00:35 +02:00
setInterval(function() {
refreshTime();
}, 59000);
refreshContent();
2014-08-31 04:00:35 +02:00
setInterval(function() {
refreshContent();
}, 60000);
loadWeather();
2014-08-31 04:00:35 +02:00
setInterval(function() {
loadWeather();
}, 900000);
l2status();
2014-08-31 04:00:35 +02:00
setInterval(function() {
l2status();
}, 60000);
2014-07-20 23:19:59 +02:00
l2events();
2014-08-31 04:00:35 +02:00
setInterval(function() {
2014-07-20 23:19:59 +02:00
l2events();
}, 3600000);
wortLuNews();
2014-08-31 04:00:35 +02:00
setInterval(function() {
wortLuNews();
}, 900000);
cflNews();
2014-08-31 04:00:35 +02:00
setInterval(function() {
cflNews();
}, 900000);
});
}(window.jQuery);
function refreshTime() {
2014-08-31 04:00:35 +02:00
$('.time').text(moment().format('HH:mm')); // 03:37
$('.date').text(moment().format('dddd, D MMMM')); // Sunday, 31 August
}
function refreshContent() {
$('#wrapper').html('');
var request = $.ajax({
2014-08-31 04:00:35 +02:00
type: 'get',
url: 'https://getcontents.herokuapp.com/?url=http%3A%2F%2Ftravelplanner.mobiliteit.lu%2Fhafas%2Fcdt%2Fstboard.exe%2Ffn%3FL%3Dvs_stb%26input%3D200404028%26boardType%3Ddep%26time%3D' + moment().format('HH') + '%3A' + moment().format('mm') + '%26selectDate%3Dtoday%26start%3Dyes%26requestType%3D0%26maxJourneys%3D10',
complete: function(response) {
2014-08-31 04:00:35 +02:00
resp = response.responseText.slice(14);
2014-08-31 04:00:35 +02:00
data = JSON.parse(resp);
2014-08-31 04:00:35 +02:00
busses = data.journey;
var content = '<div class="panel"><h1>Upcoming busses</h1>';
2014-08-31 04:00:35 +02:00
$.each(busses, function(nr, bus) {
2014-08-31 04:00:35 +02:00
var name = bus.pr;
var destination = bus.st;
2014-08-31 04:00:35 +02:00
if (bus.rt != false) {
2014-08-31 04:00:35 +02:00
var time = bus.rt.dlt;
2014-08-31 04:00:35 +02:00
} else {
2014-08-31 04:00:35 +02:00
var time = bus.ti;
2014-08-31 04:00:35 +02:00
}
2014-08-31 04:00:35 +02:00
var timeDifference;
2014-08-31 04:00:35 +02:00
var busTime = moment()
.set('hour', time.substring(0, 2))
.set('minute', time.substring(3, 5));
2014-08-31 04:00:35 +02:00
timeDifference = busTime.diff(moment(), 'minutes');
2014-08-31 04:00:35 +02:00
timeLeftMessage = 'departure in ' + timeDifference + ' minutes';
2014-08-31 04:00:35 +02:00
if (timeDifference <= 5 && timeDifference > -1) {
2014-08-31 04:00:35 +02:00
labelColor = "danger";
2014-08-31 04:00:35 +02:00
} else if (timeDifference <= 10 && timeDifference > -1) {
2014-08-31 04:00:35 +02:00
labelColor = "warning";
2014-08-31 04:00:35 +02:00
} else {
2014-08-31 04:00:35 +02:00
labelColor = "info";
timeLeftMessage = '';
2014-08-31 04:00:35 +02:00
}
2014-08-31 04:00:35 +02:00
if (name.indexOf("Bus") != -1) {
name = name.slice(name.indexOf("Bus ") + 4);
}
2014-08-31 04:00:35 +02:00
content += '<h1>' + time + ' <span class="label label-' + labelColor + ' label-lg">' + name + '</span> ' + destination + '</h1>' + timeLeftMessage;
2014-08-31 04:00:35 +02:00
});
2014-08-31 04:00:35 +02:00
$('.busses').html('');
$('.busses').append(content);
2014-08-31 04:00:35 +02:00
console.log(moment().format('YYYY.MM.DD - HH:mm:ss') + ' updated busses');
2014-08-31 04:00:35 +02:00
}
});
}
function loadWeather() {
var city = 'Bonnevoie';
2014-08-31 03:55:05 +02:00
var country = 'LU';
var appid = '64a2215ad2f5f944abd334578763726e';
var request = $.ajax({
type: 'get',
// fixme: use an api that supports https
2014-08-31 03:55:05 +02:00
url: 'https://getcontents.herokuapp.com/?url=http://api.openweathermap.org/data/2.5/weather?q=' + city + ',' + country + '&units=metric&appid=' + appid,
2014-08-31 04:00:35 +02:00
complete: function(response) {
2014-08-31 04:00:35 +02:00
data = JSON.parse(response.responseText);
weather = data.weather[0];
2014-08-31 04:00:35 +02:00
var description = weather.description;
var weatherId = weather.icon;
var temperature = formatTemp(data.main.temp);
2014-08-31 04:00:35 +02:00
$('.currentTemp').text(temperature);
$('.weatherIcon').attr('class', 'climacon ' + OWMIcon(weatherId));
2014-08-31 04:00:35 +02:00
console.log(moment().format('YYYY.MM.DD - HH:mm:ss') + ' updated weather');
}
});
}
2014-08-31 04:00:35 +02:00
function formatTemp(temperature) {
2014-08-31 04:00:35 +02:00
temperature = temperature - 273.15; // K to C
2014-08-31 04:00:35 +02:00
temperature = (temperature).toFixed(1); // 1 decimal
2014-08-31 04:00:35 +02:00
if (temperature > 10) {
temperature = Math.round(temperature); // round up to the nearest integer
}
return temperature + '°C';
}
2014-08-31 04:00:35 +02:00
function OWMIcon(imageCode) {
// Icon Name & Colour Percentage
var b = {
'01d': ["sun"],
'01n': ["moon"],
2014-08-31 04:00:35 +02:00
'02d': ["cloud sun"],
'02n': ["cloud moon"],
2014-08-31 04:00:35 +02:00
'03d': ["cloud"],
'03n': ["cloud"],
2014-08-31 04:00:35 +02:00
'04d': ["cloud"],
'04n': ["cloud"],
2014-08-31 04:00:35 +02:00
'09d': ["showers sun"],
'09n': ["showers moon"],
2014-08-31 04:00:35 +02:00
'10d': ["rain sun"],
'10n': ["rain moon"],
2014-08-31 04:00:35 +02:00
'11d': ["lightning sun"],
'11n': ["lightning moon"],
2014-08-31 04:00:35 +02:00
'13d': ["snow sun"],
'13n': ["snow moon"],
2014-08-31 04:00:35 +02:00
'50d': ["fog sun"],
'50n': ["fog moon"]
};
return b[imageCode]
}
function l2status() {
var request = $.ajax({
type: 'get',
2014-08-17 03:29:34 +02:00
url: 'https://spaceapi.syn2cat.lu/status/json',
2014-08-31 04:00:35 +02:00
complete: function(response) {
2014-08-31 04:00:35 +02:00
var status = JSON.parse(response.responseText);
2014-08-31 04:00:35 +02:00
var timeStamp = moment.unix(status.state.lastchange).fromNow();
2014-08-25 16:57:24 +02:00
2014-07-20 22:52:23 +02:00
$('.status').removeClass('open').removeClass('closed');
2014-08-31 04:00:35 +02:00
if (status.state.open) {
2014-08-25 16:57:24 +02:00
$('.status')
.addClass('open')
.html('<h1>Open</h1> Opened ' + timeStamp);
$('.hackers').html( status.sensors.people_now_present[0].value + ' people inside' );
} else {
2014-08-25 16:57:24 +02:00
$('.status')
.addClass('closed')
2014-08-31 03:47:48 +02:00
.html('<h1>Closed</h1> ' + timeStamp);
$('.hackers').html('');
}
}
});
2014-08-31 04:00:35 +02:00
console.log(moment().format('YYYY.MM.DD - HH:mm:ss') + ' updated Level2 status');
}
2014-07-20 23:19:59 +02:00
function l2events() {
var request = $.ajax({
type: 'get',
2014-08-17 04:25:48 +02:00
url: 'https://wiki.hackerspace.lu/wiki/Special:Ask/-5B-5BCategory:Event-5D-5D-20-5B-5BStartDate::-3E' + moment().format('YYYY') + '-2D' + moment().format('MM') + '-2D' + moment().format('DD') + '-5D-5D/-3FStartDate/-3FEndDate/-3FHas-20subtitle/-3FHas-20description/-3FIs-20Event-20of-20Type%3DIs-20type/-3FHas-20location/-3FHas-20picture/-3FHas-20cost/-3FCategory/format%3Djson/sort%3DStartDate/order%3Dascending/searchlabel%3DJSON-20(Internal,-20only-20upcoming-20events)',
2014-08-31 04:00:35 +02:00
complete: function(response) {
2014-07-20 23:19:59 +02:00
var l2event_name, l2event_ob;
2014-07-20 23:19:59 +02:00
var events = JSON.parse(response.responseText);
2014-07-20 23:19:59 +02:00
var output = '<div class="panel"><h1>Level 2 events</h1>';
for (l2event_name in events.results) {
var l2event_ob = events.results[l2event_name];
// calculate start date
var tsStartDate = l2event_ob.printouts.StartDate[0] * 1000;
var startDate = moment.tz(tsStartDate, "GMT");
// calculate end date
var tsEndDate = l2event_ob.printouts.EndDate[0] * 1000;
var endDate = moment.tz(tsEndDate, "GMT");
// do not show hour if event spans over entire days
if (startDate.format('HH:mm') == '00:00' && endDate.format('HH:mm') == '00:00') {
startDate = startDate.format('dddd, D MMMM');
} else {
startDate = startDate.format('dddd, D MMMM HH:mm');
}
output += '<h1>' + l2event_name + ' <small><br>' + startDate + '</small></h1>' + l2event_ob.printouts['Has description'][0];
2014-07-20 23:19:59 +02:00
};
output += "</div>";
2014-07-20 23:19:59 +02:00
2014-08-31 04:00:35 +02:00
$('.events').html('').append(output);
2014-07-20 23:19:59 +02:00
}
});
2014-08-31 04:00:35 +02:00
console.log(moment().format('YYYY.MM.DD - HH:mm:ss') + ' updated Level2 events');
2014-07-20 23:19:59 +02:00
}
function wortLuNews() {
var request = $.ajax({
type: 'get',
url: 'https://device.wort.lu/api/v303/sites/en/sections/4f4e59a1e4b056b73debc870',
2014-08-31 04:00:35 +02:00
complete: function(response) {
2014-08-31 04:00:35 +02:00
var articles = response.responseJSON.articles;
var output = '<div class="panel"><h1>News</h1>';
2014-08-31 04:00:35 +02:00
for (var ArticleNR = 0; ArticleNR < 5; ArticleNR++) {
2014-08-31 04:00:35 +02:00
var article = articles[ArticleNR];
output += '<h1>' + article.title + '</h1>' + article.teaser;
}
output += '</div>';
2014-08-31 04:00:35 +02:00
$('.news').html('').append(output);
}
});
2014-08-31 04:00:35 +02:00
console.log(moment().format('YYYY.MM.DD - HH:mm:ss') + ' updated WortLu News');
}
function cflNews() {
var request = $.ajax({
type: 'get',
url: 'https://getcontents.herokuapp.com/?url=http%3A%2F%2Fmobile.cfl.lu%2Fbin%2Fhelp.exe%2Fenl%3Ftpl%3Drss_feed_global',
2014-08-31 04:00:35 +02:00
complete: function(response) {
var cfl = response.responseText;
var output = '<div class="panel"><h1>CFL notifications</h1>';
2014-08-31 04:00:35 +02:00
$($.parseXML(cfl))
.find("item")
.each(function() {
output += '<h1>' + $(this).find("title").text() + '</h1>' + $(this).find("description").text();
2014-08-31 04:00:35 +02:00
});
output += "</div>";
2014-08-31 04:00:35 +02:00
$('.cfl').html('').append(output);
}
});
2014-08-31 04:00:35 +02:00
console.log(moment().format('YYYY.MM.DD - HH:mm:ss') + ' updated cfl News');
}