forked from 12v/mp-twitter-bios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyse.mjs
55 lines (45 loc) · 1.64 KB
/
analyse.mjs
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
import { readFileSync, writeFileSync } from 'fs';
const PARTY_ALIASES = {
"Conservative": ["Conservative", "Tory", "Tories"],
"Labour": ["Labour", "Lab"],
"Liberal Democrat": ["Liberal Democrat", "Lib Dem", "Lib Dems", "LibDem"],
"Scottish National Party": ["SNP", "Scottish National Party"],
"Democratic Unionist Party": ["DUP", "Democratic Unionist Party"],
"Sinn Féin": ["Sinn Féin", "Sinn Fein", "SF"],
"Plaid Cymru": ["Plaid Cymru", "Plaid"],
"Green Party": ["Green Party", "Green"],
"The Reclaim Party": ["Reclaim"],
"Alliance": ["Alliance"],
"Social Democratic & Labour Party": ["SDLP", "Social Democratic & Labour Party"],
"Alba Party": ["Alba"]
}
const mps = JSON.parse(readFileSync('output/members-api-and-pol-social-and-twitter.json', 'utf8'));
const results = {};
mps.forEach(mp => {
if (mp.party === "Speaker" || mp.party === "Independent") {
return;
}
if (mp.party === "Labour (Co-op)") {
mp.party = "Labour";
}
if (!PARTY_ALIASES[mp.party]) {
throw (`Unknown party ${mp.party}`)
}
if (!results[mp.party]) {
results[mp.party] = {
total: 0,
proud: [],
shy: [],
invisible: []
};
}
results[mp.party].total++;
if (!mp.twitterUsername) {
results[mp.party].invisible.push(mp);
} else if (PARTY_ALIASES[mp.party].some(alias => mp.description.toLowerCase().includes(alias.toLowerCase()))) {
results[mp.party].proud.push(mp);
} else {
results[mp.party].shy.push(mp);
}
});
writeFileSync('output/analysis.json', JSON.stringify(results, null, 2));