This repository has been archived by the owner on Aug 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
aws.js
66 lines (47 loc) · 1.56 KB
/
aws.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
var async = require('async');
var fs = require('fs');
var path = require('path');
var filenamify = require('filenamify');
var express = require('express');
const { BOT_URL, WORDS_DIR, WORDS_JSON_DIR } = require('./constants');
const WordService = require('./helpers/WordService');
const app = express();
app.get('/', (req, res) => {
});
var words = process.argv.find(x => x.indexOf('--words=') !== -1);
app.listen(1071, () => {
console.log('1071', 'dinleniyor');
if (words !== undefined) {
words = words.split('=')[1].split(',');
var res = [];
words.map(x => {
var fileName = path.join(WORDS_DIR, x + '.json');
var original_words = fs.readFileSync(fileName).toString();
original_words = JSON.parse(original_words);
res = res.concat(original_words);
});
words = res;
}
var run = (index = 0) => {
var word = words[index];
var cb = (data) => {
console.log('İstek bitti', data);
run(index + 1);
};
const fileName = path.join(WORDS_JSON_DIR, filenamify(word) + '.json');
if (fs.existsSync(fileName)) {
cb(fs.readFileSync(fileName).toString(), index);
return;
}
WordService.saveWord(word).then(res => {
fs.writeFile(fileName, res, function(err) {
if(err) {
console.log(err);
}
});
cb(JSON.stringify(res), index);
})
.catch(err => cb(err, index));
};
run();
})