forked from iP1SMS/disposable-phone-numbers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.js
47 lines (37 loc) · 1.2 KB
/
import.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
var fs = require('fs')
const getDateString = () => {
date = new Date()
year = date.getFullYear()
month = date.getMonth()+1
dt = date.getDate()
if (dt < 10) {
dt = '0' + dt
}
if (month < 10) {
month = '0' + month
}
return year+'-' + month + '-' + dt
}
// Load existing list
fs.readFile('number-list.json', 'utf8', function(err, existingContent) {
let existingNumbers = JSON.parse(existingContent)
// Load list of new numbers from file
fs.readFile('import.json', 'utf8', function(err, content) {
let newNumbers = JSON.parse(content)
for(let key in newNumbers){
existingNumbers[key] = getDateString()
}
// Order keys
existingNumbers = Object.keys(existingNumbers).sort().reduce((accumulator, currentValue) => {
accumulator[currentValue] = existingNumbers[currentValue]
return accumulator
}, {})
// Write to file
fs.writeFile("number-list.json", JSON.stringify(existingNumbers, null, 2), function(err) {
if(err) {
return console.log(err)
}
console.log("The file was saved!")
});
})
})