mirror of
https://gitlab.silvrtree.co.uk/martind2000/SODashServer.git
synced 2025-01-31 14:40:15 +00:00
112 lines
3.8 KiB
JavaScript
112 lines
3.8 KiB
JavaScript
//Var t = require('./getTimeAndDate');
|
|
|
|
|
|
var meetingStates = {
|
|
STARTING: 0,
|
|
INPROGRESS: 1,
|
|
NONE: 2,
|
|
FINISHED: 3
|
|
};
|
|
|
|
|
|
|
|
calendarInterface.prototype.getRoomStatus = function() {
|
|
|
|
|
|
var timeAndDate = new t.getTimeAndDate;
|
|
|
|
request('http://crmplace.com/censis/ical_server.php?type=ics&key=largemeetingroom&email=largemeetingroom@censis.org.uk', function(err, res, body) {
|
|
if (err) {
|
|
callback.call(null, new Error('Request failed'));
|
|
return;
|
|
}
|
|
|
|
var $ = cheerio.load(body);
|
|
var text = $('#element').text();
|
|
meetingInfo = $.html();
|
|
|
|
// Find today's date and time and convert to meeting info format
|
|
timeNow = timeAndDate.time;
|
|
dateToday = timeAndDate.date;
|
|
|
|
// Define meeting start and end identifying string
|
|
var meetingStartID = 'DTSTART;TZID=Europe/London:';
|
|
var meetingEndID = 'DTEND;TZID=Europe/London:';
|
|
var meetingDescID = 'DESCRIPTION:';
|
|
|
|
// Look for meetings taking place today
|
|
var meetingStart = new Array;
|
|
var meetingEnd = new Array;
|
|
var meetingDesc = new Array;
|
|
|
|
// Break up the file into lines.
|
|
var lines = meetingInfo.split('\n');
|
|
|
|
var meetingNum = 0;
|
|
for (i = 0; i < lines.length; i++) {
|
|
var n = lines[i].indexOf(meetingStartID);
|
|
if (n == -1) {
|
|
} else {
|
|
var meetingStartStr = lines[i];
|
|
var meetingDate = meetingStartStr.substring(meetingStartID.length, meetingStartID.length + 8);
|
|
if (meetingDate == dateToday.toString()) {
|
|
meetingStart[meetingNum] = lines[i];
|
|
meetingEnd[meetingNum] = lines[i + 1];
|
|
meetingDesc[meetingNum] = lines[i + 3];
|
|
meetingNum += 1;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
if (meetingNum == 0) {
|
|
console.log('There are no meetings scheduled for today.')
|
|
} else {
|
|
console.log('Number of meetings today: ' + meetingNum);
|
|
|
|
var projectorStatus = 0;
|
|
// Is there a meeting on now
|
|
for (m = 0; m < meetingStart.length; m++) {
|
|
if (parseInt(timeNow) == parseInt(meetingStart[m].substring(36, 40))) {
|
|
var currentMeeting = m;
|
|
} else if ((parseInt(timeNow) <= parseInt(meetingEnd[m].substring(34, 38))) && (parseInt(timeNow) > parseInt(meetingStart[m].substring(36, 40)))) {
|
|
var currentMeeting = m;
|
|
} else {
|
|
var currentMeeting = 'None';
|
|
}
|
|
|
|
}
|
|
|
|
// If there is a meeting on now, define projector status
|
|
if (currentMeeting == 'None') {
|
|
console.log('Time now: ' + timeNow);
|
|
console.log('No meeting just now.');
|
|
} else {
|
|
|
|
console.log('Current meeting is: ' + meetingDesc[currentMeeting].substring(12, meetingDesc[currentMeeting].length));
|
|
|
|
if (parseInt(timeNow) == parseInt(meetingStart[currentMeeting].substring(36, 40))) {
|
|
return meetingStates.STARTING;
|
|
} else if ((parseInt(timeNow) <= parseInt(meetingEnd[currentMeeting].substring(34, 38))) && (parseInt(timeNow) > parseInt(meetingStart[currentMeeting].substring(36, 40)))) {
|
|
return meetingStates.INPROGRESS;
|
|
} else if (parseInt(timeNow) > parseInt(meetingEnd[currentMeeting].substring(34, 38))) {
|
|
return meetingStates.NONE;
|
|
}
|
|
|
|
|
|
console.log('Time now: ' + timeNow);
|
|
console.log('Meeting start time: ' + meetingStart[currentMeeting].substring(36, 40));
|
|
console.log('Meeting end time: ' + meetingEnd[currentMeeting].substring(34, 38));
|
|
console.log('Projector Status: ' + projectorStatus);
|
|
console.log('');
|
|
|
|
// Return projectorStatus;
|
|
// module.exports.pStatus = projectorStatus;
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|