From 034697421198ff9acf9e87155bc870d1855d0bec Mon Sep 17 00:00:00 2001 From: zjamnik Date: Thu, 7 Jul 2022 08:49:41 +0200 Subject: [PATCH] redownload implemented; spellcheck --- .vscode/settings.json | 10 ++++++++++ README.md | 10 ++++++---- WNtoEmail.js | 13 +++++++++---- 3 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..010b8b6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,10 @@ +{ + "cSpell.words": [ + "mobi", + "redownload" + ], + "cSpell.ignoreWords": [ + "csstransforms", + "truyen" + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 756e63f..e63db58 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # WNtoEmail Node.js script to download new WebNovel chapters convert them to eBook and send to email. Mainly intended for sending to Kindle. -Script will pack your WebNovels into convinient eBooks, complete with cover image, metadata and table of contents. For ongoing series it will wait for a configured number of new chapters before sending a new volume to avoid spam. +Script will pack your WebNovels into convenient eBooks, complete with cover image, metadata and table of contents. For ongoing series it will wait for a configured number of new chapters before sending a new volume to avoid spam. -# Dependecies +# Dependencies It's a Node.js project so install that. Project is using `node-html-parser` and `nodemailer` libraries. It should be enough to: ``` @@ -10,6 +10,8 @@ npm install --save node-html-parser npm install --save nodemailer ``` +https://github.com/vercel/pkg for deploying to binary files. + I'm using fetch, which is an experimental feature, it might work differently on different versions. Script written on Node version `v18.4.0` > ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time @@ -81,7 +83,7 @@ OR Run the script directly from cloned project with Node.js. Intended usage is with a Task Scheduler on Windows. There shouldn't be anything OS specific. Cron on Linux should work after modifying `"converterPath"` to an appropriate command, but that's untested. -At present there is no crash resiliency, if the program crashes for any reason `"lastChapterURL"`, `"lastVolume"` and `"completed"` config will not be cosistent and needs to be corrected. There is a copy of config file created at the start. +At present there is no crash resiliency, if the program crashes for any reason `"lastChapterURL"`, `"lastVolume"` and `"completed"` config will not be consistent and needs to be corrected. There is a copy of config file created at the start. ## Send to Kindle -[Kindle help page](https://www.amazon.com/gp/help/customer/display.html?nodeId=GX9XLEVV8G4DB28H) can help you with setup. You need to assign the divice you want to use an email address (there should already be one with some random ID, you can change it something more convinient) and add your email used for sending to the allowed list. +[Kindle help page](https://www.amazon.com/gp/help/customer/display.html?nodeId=GX9XLEVV8G4DB28H) can help you with setup. You need to assign the device you want to use an email address (there should already be one with some random ID, you can change it something more convenient) and add your email used for sending to the allowed list. diff --git a/WNtoEmail.js b/WNtoEmail.js index 2d7268c..0301899 100644 --- a/WNtoEmail.js +++ b/WNtoEmail.js @@ -1,4 +1,3 @@ -//const fs = require('fs'); const fs = require('node:fs/promises'); const path = require('path'); const HTMLparser = require('node-html-parser'); @@ -39,8 +38,8 @@ function padNumber(num, len) { function log(text) { let d = new Date(); - let datetime = `${d.getFullYear()}.${padNumber((d.getMonth() + 1), 2)}.${padNumber(d.getDate(), 2)}_${padNumber(d.getHours(), 2)}:${padNumber(d.getMinutes(), 2)}:${padNumber(d.getSeconds(), 2)}.${padNumber(d.getMilliseconds(), 3)}`; - fs.appendFile(cleanPath(`./WNtoEmail.log`), `${datetime} ${text}\n`); + let dateTime = `${d.getFullYear()}.${padNumber((d.getMonth() + 1), 2)}.${padNumber(d.getDate(), 2)}_${padNumber(d.getHours(), 2)}:${padNumber(d.getMinutes(), 2)}:${padNumber(d.getSeconds(), 2)}.${padNumber(d.getMilliseconds(), 3)}`; + fs.appendFile(cleanPath(`./WNtoEmail.log`), `${dateTime} ${text}\n`); } async function mkDir(dirPath) { @@ -191,7 +190,7 @@ function sendEbook(subject, ebookAttachments) { } } -async function fetch_smth(URL, hosting) { +async function fetch_something(URL, hosting) { let fetchURL = await fetch(URL); if (fetchURL.ok) { @@ -317,6 +316,12 @@ async function main() { let chapters = []; let nextChapterURL; + if (novel['redownload']) { + novel['completed'] = false; + novel['lastChapterURL'] = false; + novel['lastVolume'] = 0; + } + if (!novel['completed']) { let novelInfo = await fetchNovelInfo(novel['novelURL'], 'NF');