-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimporter.mjs
executable file
·41 lines (31 loc) · 965 Bytes
/
importer.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
#!node_modules/.bin/zx
import { fs, path } from 'zx';
import _ from 'lodash';
import { MongoClient } from 'mongodb';
const listwlcc = [
"BE", "BG", "CZ", "DK", "DE", "EE", "IE",
"GR", "ES", "FR", "HR", "IT", "CY", "LV",
"LT", "LU", "HU", "MT", "NL", "AT", "PL",
"PT", "RO", "SI", "SK", "FI", "SE"
];
const root = path.join("site", "static", "MEPs");
const client = new MongoClient('mongodb://127.0.0.1:27017/faces');
await client.connect();
for (const TLC of listwlcc) {
const srcjson = path.join(root, `ppls-${TLC}.json`);
const ppls = await fs.readJSON(srcjson);
console.log(`Adding ${ppls.length}, for country ${TLC}`);
const mepobjs = _.map(ppls, function(mep) {
let chunks = mep.urlimg.split('/');
let id = chunks.pop();
id = id.replace(/\.jpg/, '');
return {
id,
...mep
};
});
await client.db()
.collection('meps').insertMany(mepobjs);
}
await client.close();
console.log("Aquisition done!");