Skip to content

Commit

Permalink
jwmynwt
Browse files Browse the repository at this point in the history
  • Loading branch information
Khen Solomon Lethil committed Aug 24, 2019
1 parent 5b4c1cf commit 5c8fcd5
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bibleMsg.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {
},
infoMissing: function(){
// Required: info > identify,name,shortname,year for final output!
return '\n...\x1b[31info\x1b[0m > \x1b[36midentify\x1b[0m, \x1b[36mname\x1b[0m, \x1b[36mshortname\x1b[0m, \x1b[36myear\x1b[0m for final output!';
return '\n...\x1b[31mmissing\x1b[0m > \x1b[36midentify\x1b[0m, \x1b[36mname\x1b[0m, \x1b[36mshortname\x1b[0m, \x1b[36myear\x1b[0m for final output!';
},
book: function(bId,cId,bookName,chapterName){
// var spaces = (bId < 10)?' ':'';
Expand Down
4 changes: 2 additions & 2 deletions book.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Lai Siangtho",
"updated": "2019-08-24T17:44:14.651Z",
"version": 252,
"updated": "2019-08-24T18:23:18.429Z",
"version": 253,
"book": [
{
"identify": "ddb1931",
Expand Down
184 changes: 184 additions & 0 deletions json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
const path = require('path');
// const fs = require('fs-extra');
// const sqlite3 = require('sqlite3');
var param={};

var json = {
// category:{}
fileTask:function(){
// return path.resolve(param.root,'json',param.task.json.extension.replace('*',param.bookIdentify));
return path.resolve(param.root,'json',param.json.file.name.replace('*',param.bookIdentify));
},
fileCategory:function(){
return path.resolve(param.root,param.json.file.name.replace('*','category'));
}
},

// var filename = param.json.file.name.replace('*',param.bookIdentify);
// param.json.read(path.resolve(param.root,param.job.name,filename)).then(function(data){

readJSON = function() {
return new Promise(function(resolve, reject) {
if (!param.bookIdentify) return reject(`...\x1b[35m${param.bookIdentify}\x1b[0m!`);
param.json.read(json.fileCategory()).then(function(category){
json.category = category;
param.json.read(json.fileTask()).then(function(e){
resolve(e);
},function(e){
reject(e);
});
},function(e){
reject(e);
});
});
},
writeJSON = function(data) {
var indentation = param.args.length > 2;
var tmp = param.json.stringify(data,indentation);
return param.json.write(json.fileTask(),tmp);
},
scanJSON = function(data){
return new Promise(function(resolve, reject) {
try {
var result={
info:parseInfo(data.info),
note:parseNote(data.note),
digit:parseDigit(data.digit),
language:parseLanguage(data.language),
testament:parseTestament(data.testament),
story:parseStory(data.story),
book:parseBook(data.book)
};
return resolve();
} catch (e) {
return reject(e);
}
});
},
parseInfo = function(data){
return data;
},
parseNote = function(data){
return data;
},
parseDigit = function(data){
return data;
},
parseLanguage = function(data){
return data;
},
parseTestament = function(data){
return data;
},
parseStory= function(data){
return data;
},
parseBook = function(data){
var categoryBook = json.category.book;
var bookTofix = 0;
var bookTotal = Object.keys(categoryBook).length;
var bookCount = 0;
var chapterTofix = 0;
var verseTofix = 0;
var result={};
for (const bId in data) {
if (data.hasOwnProperty(bId)) {
bookCount++;
var categoryBookCurrent = categoryBook[bId];
const book = data[bId];
if (book.hasOwnProperty('chapter')){
var chapterTotal = categoryBookCurrent.c;
var chapterCount = Object.keys(book.chapter).length;
var logBookId = bId;
if (chapterCount != chapterTotal){
logBookId = logBookId+`\x1b[0m(\x1b[31m${chapterTotal}-${chapterCount}\x1b[0m)`;
chapterTofix++;
}
param.msg.book(logBookId,null,book.info.name);
// param.msg.book(logBookId,null);
// console.log(book.info);

// var bookLength = book.info.name.length;
// var bookNameWithSpace = book.info.name + new Array(30 - bookLength).join(' ');
result[bId]={
chapter:{}
};
for (const cId in book.chapter) {
if (book.chapter.hasOwnProperty(cId)) {
const chapter = book.chapter[cId];
if (chapter.hasOwnProperty('verse')){
result[bId].chapter[cId]={
verse:{}
};
var verseTotal = categoryBookCurrent.v[cId-1];
var verseCount = Object.keys(chapter.verse).length;
if (verseCount != verseTotal){
verseTofix++;
}
for (const vId in chapter.verse) {
if (chapter.verse.hasOwnProperty(vId)) {
var newVerse={};
const verse = chapter.verse[vId];
if (verse.hasOwnProperty('text') && verse.text !="") {
newVerse.text=verse.text;
} else {
console.log('verse has no text',bId,cId,vId);
}
if (verse.hasOwnProperty('title') && verse.title !="") newVerse.title=verse.title;
if (verse.hasOwnProperty('merge') && verse.merge !="") {
verseTofix--;
newVerse.merge=verse.merge;
}
if (verse.hasOwnProperty('ref') && verse.ref !="") newVerse.ref=verse.ref;
result[bId].chapter[cId].verse[vId]=newVerse;
}
}
var verseStatus = verseCount == verseTotal?cId:`${cId}(\x1b[31m${verseTotal}-${verseCount}\x1b[33m)`;
param.msg.chapter(verseStatus);
} else {
param.msg.chapter(`\x1b[31m${cId}\x1b[0m?`);
}
}
}
} else {
// console.log('has no chapter');
param.msg.chapter('no chapter');
bookTofix++;
}
}
}
var bookPassed = bookTofix == 0;
var chapterPassed = chapterTofix == 0;
var versePassed = verseTofix == 0;
// var tofixed = bookTofix + chapterTofix + verseTofix;
console.log(`\n...status > book: \x1b[31m${bookPassed}\x1b[0m chapter: \x1b[31m${chapterPassed}\x1b[0m verse: \x1b[31m${versePassed}\x1b[0m`);
console.log(`...to fix > book: \x1b[31m${bookTofix}\x1b[0m chapter: \x1b[31m${chapterTofix}\x1b[0m verse: \x1b[31m${verseTofix}\x1b[0m`);
// data.forEach(function(bid){
// console.log('bookid',bid);
// });
return result;
};

module.exports = {
main:function(usr) {
param = usr;
return new Promise(function(resolve, reject) {
readJSON().then(function(resultOrginal){
// console.log(resultOrginal);
scanJSON(resultOrginal).then(function(resultFinal){
resolve();
// return writeJSON(resultFinal).then(function(e){
// // resolve(resultFinal);
// resolve();
// },function(e){
// reject(e);
// })
},function(e){
reject(e);
});
},function(e){
reject(e);
});
});
}
};
2 changes: 1 addition & 1 deletion json/jwmynwt.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions jwb.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var requestBookId = '';
// https://www.jw.org/my/စာပေများ/သမ္မာကျမ်းစာ/nwt/ကျမ်း/json/html/19105024-19105025
// https://www.jw.org/my/စာပေများ/သမ္မာကျမ်းစာ/nwt/ကျမ်း/ကမ္ဘာဦး/1/

// node bible jwb 348
// node bible jwb jwmynwt
// node bible json jwmynwt
// node bible jwb my/var --indentation
// node bible jwb my/စာပေများ/သမ္မာကျမ်းစာ/nwt/ကျမ်း/ကမ္ဘာဦး/1 --indentation
// node bible jwb /my/စာပေများ/သမ္မာကျမ်းစာ/nwt/ကျမ်း/ကမ္ဘာဦး/1 --indentation
Expand Down Expand Up @@ -174,8 +175,11 @@ function requestChapter() {
verseStory.push(makeup(e));
});
});
// NOTE id="v38001001"
// NOTE id="v1001002"
await root.querySelectorAll('#bibleText span.verse').forEach(async function(v) {
var verseId = v.attributes.id.substring(5,8).replace(/^0+/, '');
// var verseId = v.attributes.id.substring(5,8).replace(/^0+/, '');
var verseId = v.attributes.id.substr(v.attributes.id.length - 3).replace(/^0+/, '');
var verseContent = v.querySelectorAll('span').map(function(e){
return e.innerHTML.replace(/(<([^>]+)>)/g,'--').replace(/--([*|+])--/g,' ');
});
Expand Down

0 comments on commit 5c8fcd5

Please sign in to comment.