Frontend: Implement time parsing
This commit is contained in:
parent
d8d2799145
commit
2d3abdc84c
@ -39,7 +39,7 @@ async function arrDepBoard(CRS){
|
|||||||
return reply
|
return reply
|
||||||
} else if (valid == false) {
|
} else if (valid == false) {
|
||||||
log.out(`ldbService.arrDepBoard: Invalid 3ALPHA for lookup: ${CRS}`)
|
log.out(`ldbService.arrDepBoard: Invalid 3ALPHA for lookup: ${CRS}`)
|
||||||
return {status: false, reason: "Invalid CRS/3alpha code"};
|
return {GetStationBoardResult: "not available", Reason: `The CRS code ${CRS} is not valid`, Why: `Sometimes a station will have more than one CRS - for example Filton Abbey Wood has FIT and FAW however schedules are only available when looking up with FIT - this is how the National Rail Enquiries systems work.`};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,20 +3,21 @@ init()
|
|||||||
/* Supporting Functions */
|
/* Supporting Functions */
|
||||||
async function init() {
|
async function init() {
|
||||||
var stn = await getQuery("stn");
|
var stn = await getQuery("stn");
|
||||||
console.log(`Looking up: ${stn}`);
|
log(`init: Looking up: ${stn}`);
|
||||||
var sv = await getQuery("sv");
|
var sv = await getQuery("sv");
|
||||||
console.log(`Staff Verstion: ${sv}`);
|
log(`init: Staff Version: ${sv}`);
|
||||||
if (sv === 'true') {
|
if (sv === 'true') {
|
||||||
console.log("Staff Version not supported yet")
|
log("init: Staff Version not supported yet.")
|
||||||
|
log("init: Unable to proceed.")
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
var data = await publicLdb(stn)
|
var data = await publicLdb(stn)
|
||||||
console.log("Fetched LDB Data")
|
log("init: Fetched LDB Data")
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
var data = null
|
var data = null
|
||||||
console.log("Unable to fetch LDB data")
|
log("init: Unable to fetch LDB data")
|
||||||
} finally {
|
} finally {
|
||||||
console.log(data)
|
log(data)
|
||||||
parseLdb(data)
|
parseLdb(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -42,13 +43,19 @@ async function setHeaders(title,time){
|
|||||||
var prefix = `OwlBoard - `
|
var prefix = `OwlBoard - `
|
||||||
document.title = `${prefix}${title}`
|
document.title = `${prefix}${title}`
|
||||||
document.getElementById("station_name").innerHTML = title
|
document.getElementById("station_name").innerHTML = title
|
||||||
|
document.getElementById("fetch_time").innerHTML = time.toLocaleTimeString()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function parseLdb(data) {
|
async function parseLdb(data) {
|
||||||
var stationName = data.GetStationBoardResult.locationName;
|
var stationName = data.GetStationBoardResult.locationName;
|
||||||
console.log(`Data ready for ${stationName}`);
|
log(`parseLdb: Data ready for ${stationName}`);
|
||||||
var generateTime = await data.GetStationBoardResult.generatedAt;
|
var generateTime = new Date(await data.GetStationBoardResult.generatedAt);
|
||||||
console.log(`Data prepared at ${generateTime}`)
|
log(`parseLdb: Data prepared at ${generateTime.toLocaleString()}`)
|
||||||
setHeaders(stationName, generateTime);
|
setHeaders(stationName, generateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log Helper
|
||||||
|
function log(msg) {
|
||||||
|
var time = new Date().toISOString();
|
||||||
|
console.log(`${time} - ${msg}`)
|
||||||
|
}
|
Reference in New Issue
Block a user