This repository has been archived by the owner on May 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexceljson_Portugal.js
142 lines (126 loc) · 4.22 KB
/
exceljson_Portugal.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
'use strict';
const excelToJson = require('convert-excel-to-json');
const glob = require("glob");
const glob_jsonlocation = "source-data/dataPortugal/*.xlsx";
const glob_options = {};
glob(glob_jsonlocation, glob_options, function (er, filelist) {
if (er) {
console.log(er);
}
var resultsArray = [];
for (var i = 0; i < filelist.length; i++) {
const result = excelToJson({
sourceFile: filelist[i],
header:{
// Is the number of rows that will be skipped and will not be present at our result object. Counting from top to bottom
rows: 1
},
sheets: [{
name: 'Serviços Públicos',
range: 'A1:L2',
columnToKey: {
A: 'PublicService_id',
H: 'PublicService_name',
I: 'PublicService_description',
L: 'PublicService_keywords'
}
},
{
name: 'Âmbito Territorial',
range: 'A1:B2',
columnToKey: {
B: 'PublicService_spatial'
}
},
{
name: 'Eventos de Vida',
columnToKey: {
B: 'LifeEvent_id'
}
},
{
name: 'Eventos de Negócio',
columnToKey: {
B: 'BusinessEvent_id'
}
},
{
name: 'Entidades',
range: 'A1:C2',
columnToKey: {
B: 'PublicOrganization_id'
}
},
{
name: 'Requisitos',
columnToKey: {
B: 'hasInput_id',
C: 'hasInput_name',
D: 'hasInput_description'
}
},
{
name: 'Legislação',
columnToKey: {
B: 'hasFormalFramework_id',
C: 'hasFormalFramework_name',
D: 'hasFormalFramework_description'
}
},
{
name: 'Regras',
columnToKey: {
B: 'follows_id',
C: 'follows_name',
D: 'follows_description'
}
},
{
name: 'Taxas e Custos',
columnToKey: {
B: 'hasCost_id',
D: 'hasCost_description',
E: 'hasCost_value'
}
},
{
name: 'Serviços Relacionados',
columnToKey: {
B: 'related_id'
}
}]
});
resultsArray.push(result);
}
const fs = require('fs');
var content = JSON.stringify(resultsArray);
content = replaceAll(content, "Serviços Públicos", "PublicService");
content = replaceAll(content, "Âmbito Territorial", "Spatial");
content = replaceAll(content, "Eventos de Vida", "LifeEvent");
content = replaceAll(content, "Eventos de Negócio", "BusinessEvent");
content = replaceAll(content, "Entidades", "CompetentAuthority");
content = replaceAll(content, "Requisitos", "hasInput");
content = replaceAll(content, "Legislação", "hasFormalFramework");
content = replaceAll(content, "Regras", "follows");
content = replaceAll(content, "Taxas e Custos", "hasCost");
content = replaceAll(content, "Serviços Relacionados", "related");
content = content.replace(/\\n/g, "\\n")
.replace(/\\'/g, "\\'")
.replace(/\\"/g, '\\"')
.replace(/\\&/g, "\\&")
.replace(/\\r/g, "\\r")
.replace(/\\t/g, "\\t")
.replace(/\\b/g, "\\b")
.replace(/\\f/g, "\\f")
.replace(/<(?:.|\n)*?>/gm, ' ')
.replace(/\ /g, ' ');
fs.writeFile("./tmp/dataPortugal.json", content, 'utf8', function (err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});
});
function replaceAll(str, find, replace) {
return str.replace(new RegExp(find, 'g'), replace);
}