-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
67 lines (62 loc) · 1.89 KB
/
index.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
/*
* This file is part of fake-italian-data
*
* Copyright (c) 2021 Dyne.org foundation
* designed, written and maintained by Puria Nafisi Azizi <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License v3.0
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* Along with this program you should have received a copy of the
* GNU Affero General Public License v3.0
* If not, see http://www.gnu.org/licenses/agpl.txt
*
* Last modified by Puria Nafisi Azizi
* on Fri Apr 30 2021
*/
const fs = require("fs");
const faker = require("faker/locale/it");
const csv = require("csv-stringify");
const cf = require("codice-fiscale-js");
const N = 200000;
const comuni = JSON.parse(fs.readFileSync("comuni.json"));
const genders = ["M", "F"];
const comune = () => {
return comuni[Math.floor(Math.random() * comuni.length)];
};
const gender = () => {
return genders[Math.floor(Math.random() * genders.length)];
};
let i = N;
const data = [["Nome", "Cognome", "CF", "email", "cellulare"]];
while (i--) {
const birth_date = faker.date.between("1900-01-01", "2002-01-01");
const birthplace = comune();
const u = {
name: faker.name.firstName(),
surname: faker.name.lastName(),
gender: gender(),
day: birth_date.getDate(),
month: birth_date.getMonth() + 1,
year: birth_date.getFullYear(),
birthplace: birthplace.nome,
birthplaceProvincia: birthplace.sigla,
};
try {
data.push([
u.name,
u.surname,
new cf(u).code,
faker.internet.email(),
faker.phone.phoneNumber(),
]);
} catch {}
}
csv(data, { quoted: true }, (e, o) => {
console.log(o);
});