-
Notifications
You must be signed in to change notification settings - Fork 0
/
reload2.js
66 lines (49 loc) · 1.81 KB
/
reload2.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
"use strict";
require("es6-shim");
var fs = require('graceful-fs');
var csv = require('csv-parser');
var glob = require("glob");
var net = require('net');
var PRIVATE = require('./PRIVATE.json');
var connectInfo = PRIVATE.connectInfo;
var uniques = new Set();
glob('data2/*.txt', function (er, files) {
files.forEach(function(file){
console.log("opening file ", file);
new Promise(function(resolve, reject){
// if new phone number create socket
var ci = JSON.parse(JSON.stringify(connectInfo));
var phone = file.split("/")[1].replace(".txt", "");
console.log('trying new connection to', phone);
ci["phoneNumber"] = "+" + phone;
var socket = net.connect(ci);
socket.on('connect', function(){
console.log('connected to the server');
socket.write("phoneNumber=" + ci.phoneNumber + "\n");
resolve(socket);
});
socket.on('error', function(){
console.log('error in conection ', error);
reject(error);
});
})
.then(function(socket){
console.log("processing file ", file)
fs.readFile(file, function (err, data) {
if (err) throw err;
var smss = data.toString().split("\n");
smss.forEach(function(sms){
// if this message was not already persited
if (!uniques.has(file + sms)){
uniques.add(file + sms);
console.log("sending ", sms);
socket.write(sms + "\n");
}
})
});
})
.catch(function(error){
console.log(error);
})
});
})