-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate_paragraphs.js
72 lines (63 loc) · 2.36 KB
/
update_paragraphs.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
68
69
70
71
72
"use strict";
var ask = require("./helpers/ask.js").ask;
ask("Enter Language: (en) ", function (lang)
{
var config,
db,
fs,
lang_obj,
queries = [];
if (!lang) {
lang = "en";
}
ask("Enter file to use: (../paragraph changes)", function (filename)
{
var book = -1,
new_file = "";
if (!filename) {
filename = "../paragraph changes";
}
fs.readFileSync(filename, "utf8").split(/\r?\n/g).forEach(function (el)
{
var possible_book = el.match(/^(\S+)/),
verseID;
/// Is it a book reference?
if (possible_book !== null) {
book = possible_book.input.trim();
/// Add it to the new file.
new_file += el + "\n";
/// Is it a verese reference with nothing after it (e.g., no question mark at the end)?
} else if (book !== -1 && /\d$/.test(el)) {
verseID = Number(lang_obj.determine_reference(book + " " + el.trim()));
if (verseID > 1) {
/// Store queries for later execution.
queries[queries.length] = "UPDATE `bible_" + lang + "` SET paragraph = (!paragraph) WHERE verseID = " + verseID + " ORDER BY id LIMIT 1";
} else {
/// This was not a valid verse reference, so don't remove it.
new_file += el + "\n";
}
} else {
new_file += el + "\n";
}
});
db.query_arr(queries, function (data, err)
{
if (err && err.length) {
console.log("ERROR");
console.log(err);
console.log("Something didn't work.");
} else {
/// Backup old file.
fs.renameSync(filename, filename + "_" + Date.now())
/// Create new paragraph file.
fs.writeFileSync(filename, new_file, "utf8");
}
process.exit();
});
});
/// Load the modules while the user is typing.
config = require("./config.js").config;
db = require("./helpers/db.js").db;
fs = require("fs");
lang_obj = require(config.static_path + "js/lang/" + lang + ".js").BF.langs[lang];
});