-
Notifications
You must be signed in to change notification settings - Fork 0
/
scannor-oeamtc.js
52 lines (46 loc) · 1.36 KB
/
scannor-oeamtc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const https = require("https");
const moment = require("moment");
const Tools = require("./tools.js");
const SOURCE = "https://www.oeamtc.at/verkehrsservice/proxy.php?url=current/?count=9999&include=cameras";
const TUNNEL = "Plabutsch";
const BLOCKAGE = "Sperre";
const DESC_ID = "oeamtc.long-description";
const TIME_ID = "oeamtc.start-time";
const ROUTE_ID ="oeamtc.routeId";
const TYPE_ID = "oeamtc.type";
function fetch(data) {
return JSON.parse(data)["contents"]["oeamtc.traffic-searchresult"]["oeamtc.list"]["oeamtc.traffic"];
}
function isTunnelBlocked(traffic) {
if(traffic == null) {
Tools.log("Could not fetch traffic data.");
return null;
}
const ID = "A9";
var incident = traffic.find(
n => n[ROUTE_ID] === ID && n[TYPE_ID] === BLOCKAGE &&
n[DESC_ID].indexOf(TUNNEL) !== -1 && isToday(n));
return incident === undefined ? null : incident[DESC_ID];
}
function isExpresswayBlocked(traffic) {
const ID = "S35";
var incident = traffic.find(
n => n[ROUTE_ID] === ID && n [TYPE_ID] === BLOCKAGE &&
isToday(n));
return incident === undefined ? null : incident[DESC_ID];
}
function isToday (n) {
const time = n[TIME_ID];
const now = moment();
const result = moment(time).isSame(now, "day");
return result;
}
if(typeof module !== "undefined") {
module.exports = {
loader: https,
SOURCE,
fetch,
isTunnelBlocked,
isExpresswayBlocked
};
}