-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparking.js
101 lines (84 loc) · 3.09 KB
/
parking.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const fs = require('fs');
const got = require('got');
const url = 'http://datatank.stad.gent/4/mobiliteit/bezettingparkingsrealtime.json';
const base = 'https://osoc16.github.io/jekyll-term-generator/parking/terms/';
const outputFile = "_data/parking.json";
let graph = [];
let context = {
"lastModifiedDate": "https://schema.org/dateModified",
"name": "http://schema.org/name",
"description": "http://schema.org/description",
"latitude": "http://schema.org/latitude",
"longitude": "http://schema.org/longitude",
// "address": "https://schema.org/streetAddress", //todo: split up to actual address, not both
// "contactInfo": "https://pending.schema.org/servicePhone", //todo: split up phone
"address": "https://schema.org/adress",
"contactInfo": "https://schema.org/text",
// "city": {
// "id": 1004,
// "name": "https://schema.org/name"
// },
// "parkingServer": {
// "id": 1005,
// "name": "https://schema.org/name"
// },
// "suggestedFreeThreshold": 5, // temporarily deleted
// "suggestedFullThreshold": 5, // temporarily deleted
// "capacityRounding": 1, // temporarily deleted
"openingTimes": "http://schema.org/openingHours",
// "openingTimes": [{
// "days": ["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"],
// "from": "00:00",
// "to": "23:59"
// }],
"parkingStatus": "http://vocab.datex.org/terms#parkingStatusPublication", // not sure
"availableCapacity": "http://vocab.datex.org/terms#parkingNumberOfVacantSpaces",
"totalCapacity": "http://vocab.datex.org/terms#totalCapacity",
"openingStatus": "http://vocab.datex.org/terms#parkingSiteOpeningStatus",
"suggestedCapacity": "http://vocab.datex.org/terms#ParkingStatusValidity",
"activeRoute": "http://vocab.datex.org/terms#parkingRoute",
// },
// "@id": "https://osoc16.github.io/mobylink/parking/#18417"
};
let jsonld = {};
got(url).then(response => {
let data = JSON.parse(response.body);
for (let space of data) {
// make the id into a url
space['@id'] = `${base}#${space.id}`;
delete space.id;
// make the parkingstatus conform
if (space.parkingStatus.open) {
space.parkingStatus.openingStatus = 'open';
} else {
space.parkingStatus.openingStatus = 'closed';
}
delete space.parkingStatus.open;
// delete what isn't parseable
delete space.suggestedFreeThreshold;
delete space.suggestedFullThreshold;
delete space.capacityRounding;
// fix the time
var lastDate = (space.parkingStatus.lastModifiedDate).replace(/\//g, '-');
var d = lastDate.split(' ')[0];
var dArr = d.split('-');
dArr = dArr.sort(() => 1);
d = dArr.join('-');
var hour = lastDate.split(' ')[1]
lastDate = d + ' ' + hour;
space.parkingStatus.lastModifiedDate = new Date(lastDate).toISOString();
// set the type
// space['@type'] = '';
graph.push(space);
};
jsonld = {
'@context': context,
'@graph': graph
};
fs.writeFile(outputFile, JSON.stringify(jsonld), function(err) {
if (err) {
return console.log(err);
}
console.log("The data was saved!");
});
});