-
Notifications
You must be signed in to change notification settings - Fork 18
/
confirm_merge.js
executable file
·47 lines (41 loc) · 1.32 KB
/
confirm_merge.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
#!/usr/bin/env node
const fs = require('fs');
let hash = {},
schools = fs.readFileSync('data/school.txt', 'utf8').trim().split('\n');
for (let [idx, line] of schools.entries()) {
line = line.trim();
if (!line.length || line[0] === '#') continue;
hash[line.split(',')[2]] = idx;
}
let n = schools.length;
let data = fs.readFileSync('dist/merge_preview.txt', 'utf8').split('\n');
for (let line of data) {
line = line.trim();
if (!line.length || line[0] === '#') continue;
let [cmd, ...data] = line.split(' ');
switch (cmd) {
case 'b': {
let [name, origin] = data;
let idx = hash[origin];
console.assert(idx != null, line);
schools[idx] += `,${name}`;
break;
}
case 'f': {
let [name, origin] = data;
let idx = hash[origin];
console.assert(idx != null, line);
let segments = schools[idx].split(',');
segments.splice(2, 0, name);
schools[idx] = segments.join(',');
break;
}
case 'c': {
let [province, city, name] = data;
schools.push(`${province},${city},${name}`);
hash[name] = n++;
break;
}
}
}
fs.writeFileSync('data/school_new.txt', schools.join('\n') + '\n', 'utf8');