From 0d6af8b6947e252b01152834693e4d35157f88ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=8F=E6=B5=B7=E8=BE=89?= Date: 2018年5月12日 11:49:18 +0800 Subject: [PATCH 01/10] =?UTF-8?q?chore:=20readme=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 59cdeb5..4ef59fc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,15 @@ # 小说更新 +## 使用 + +### 部署 +1. npm run dev + +## 本地开发 +2. npm run start + ## 注意事项 + 1. 使用了gm,需要安装graphicsmagick > http://www.icafebolger.com/linux/linuxgraphicsmagic.html 2. 使用了puppetter,在centerOs等linux上需要安装依赖,同时不可以使用sandbox From d01e583f9bebd0b020d303e322c0a757f935e735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=8F=E6=B5=B7=E8=BE=89?= Date: 2018年5月12日 11:49:56 +0800 Subject: [PATCH 02/10] =?UTF-8?q?chore:=20readme=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4ef59fc..1aef4e2 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ 1. 把小说的更新拉下来,自动邮件推送给我。 2. 可以远程设置我要添加的小说和url。用telegram实现聊天机器人 +3. ci From 195f45b0d02f9f7276c57ad0afec1b3b144ea840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=8F=E6=B5=B7=E8=BE=89?= Date: Fri, 8 Jun 2018 15:40:07 +0800 Subject: [PATCH 03/10] =?UTF-8?q?bugfix:=20=E6=94=B9=E5=8F=98=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=A0=87=E5=87=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constant.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constant.js b/src/constant.js index 74d9db0..585b183 100644 --- a/src/constant.js +++ b/src/constant.js @@ -9,7 +9,7 @@ const PREV_PICTURE_SUFFIX = 'prev'; const NEXT_PICTURE_SUFFIX = 'next'; // 图片是否相等判断标准,大于这个值就不相等 -const PICTURE_TOLERANCE = 0.000; +const PICTURE_TOLERANCE = 0.001; // noteMap 小说的map数据机构。小说名为key,url为value const NOTE_MAP = { From f5e869d80ad2a0d072e97f181c920181ec6348ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=8F=E6=B5=B7=E8=BE=89?= Date: Sat, 3 Nov 2018 11:52:37 +0800 Subject: [PATCH 04/10] =?UTF-8?q?feature:=20config=20=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++--- config.json | 16 +++++++++++++ index.js | 41 ++++++++++++++++---------------- package.json | 4 ++-- scripts/pictures_folder_exist.js | 17 ------------- scripts/prepare.js | 28 ++++++++++++++++++++++ src/config.json | 16 +++++++++++++ src/constant.js | 19 ++++++++------- src/mail.js | 9 +++---- src/picture_utils.js | 4 ++-- 10 files changed, 104 insertions(+), 56 deletions(-) create mode 100644 config.json delete mode 100644 scripts/pictures_folder_exist.js create mode 100644 scripts/prepare.js create mode 100644 src/config.json diff --git a/README.md b/README.md index 1aef4e2..4199da0 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ ## 使用 +在文件下改变config.json中的内容。将其按照自己的需要改变。(主要是邮箱授权码和小说url) + ### 部署 1. npm run dev @@ -23,13 +25,11 @@ 5. 将小说的url和截图发给我 (完成) 6. 定时任务执行 (完成) 7. 对广告的解决方法 -8. config文件 +8. config文件(完成) 9. 将log改变为真的log,而不是console.log 10. pictures文件夹的检查 (完成) - - ## 附加功能(在基本功能完成的基础上) 1. 把小说的更新拉下来,自动邮件推送给我。 diff --git a/config.json b/config.json new file mode 100644 index 0000000..b1a6de6 --- /dev/null +++ b/config.json @@ -0,0 +1,16 @@ +{ + "NOTE_MAP": { + "星辰之主": "http://www.booktxt.net/2_2982/", + "打开你的任务日志": "http://www.biqugev.com/27_27360/", + "诡秘之主": "https://www.biquge.com.tw/19_19485/", + "黑龙法典": "http://www.biquge.com.tw/19_19575/" + }, + "TARGET_MAIL": { + "address": "baihaihui131225@gmail.com" + }, + "SOURCE_MAIL": { + "address": "2911403289@qq.com", + "password": "xxxxxx", + "host": "smtp.qq.com" + } +} diff --git a/index.js b/index.js index 5613f3e..c00c20d 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,7 @@ const puppeteer = require('puppeteer'); const schedule = require('node-schedule'); -const { rename_picture, compare_picture, check_picture_exit, delete_picture } = require('./src/picture_utils'); +const { rename_picture, compare_picture, check_picture_exist, delete_picture } = require('./src/picture_utils'); const { log, create_base_error, create_base_info } = require('./src/log'); const { send_mail, get_mail_option } = require('./src/mail'); const { CHECK_INTERVAL, NOTE_MAP, NEXT_PICTURE_SUFFIX, PREV_PICTURE_SUFFIX, DIR_PATH } = require('./src/constant'); @@ -39,31 +39,36 @@ const get_picture = async (name, url) => { } }; -main = () => { +const main = () => { Object.entries(NOTE_MAP).forEach(async ([note_name, note_url]) => { + + // 常量 const prev_picture_name = `${note_name}${PREV_PICTURE_SUFFIX}.png`; const next_picture_name = `${note_name}${NEXT_PICTURE_SUFFIX}.png`; - const next_picture_path = `${DIR_PATH}/${next_picture_name}`; const prev_picture_path = `${DIR_PATH}/${prev_picture_name}`; - if (check_picture_exit(prev_picture_path)) { - // prevPage存在,拉nextPage + // 检查prev picture照片是否存在 + const is_prev_picture_exist = check_picture_exist(prev_picture_path); + + // prevPage存在,拉nextPage + if (is_prev_picture_exist) { await get_picture(next_picture_name, note_url); - // 比较过后的回调函 const _cb = is_picture_equal => { + // 如果picture相同,说明没有更新,删除nextPage if (is_picture_equal) { - // 如果picture相同,说明没有更新 log(create_base_info(`<<${note_name}>>没有更新`)); - - // 删除nextPage delete_picture(next_picture_path); - } else { - // 如果picture不相同,说明更新 + } + + // 如果picture不相同,说明更新 + // 发送mail,通知我小说更新了 + // 删除prevPicture + // 将nextPicture改名为prevPicture + if(!is_picture_equal){ log(create_base_info(`<<${note_name}>>更新了`)); - // 发送mail,通知我小说更新了 const mail_option = get_mail_option(null, { subject: `<<${note_name}>>更新了`, html: `${note_name}`, @@ -72,12 +77,8 @@ main = () => { path: next_picture_path, }, }); - send_mail(mail_option, () => { - // 删除prevPicture delete_picture(prev_picture_path); - - // 将nextPicture改名为prevPicture rename_picture(next_picture_path, prev_picture_path); }); } @@ -85,13 +86,14 @@ main = () => { // 比较照片 compare_picture(next_picture_path, prev_picture_path, _cb); - } else { - // prevPage不存在,拉prevPage + } + + // prevPage不存在,拉prevPage,并通知 + if(!is_prev_picture_exist){ await get_picture(prev_picture_name, note_url); log(create_base_info(`新小说<<${note_name}>>`)); - // 通知我,这是新加的小说 const mail_option = get_mail_option(null, { subject: `新小说<<${note_name}>>`, html: `${note_name}`, @@ -100,7 +102,6 @@ main = () => { path: prev_picture_path, }, }); - send_mail(mail_option); } }); diff --git a/package.json b/package.json index 27a23f2..6c8a10b 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "description": "", "main": "index.js", "scripts": { - "prepare": "node ./scripts/pictures_folder_exist.js", - "start": "npm run preapre && node ./index.js", + "prepare": "node ./scripts/prepare.js", + "start": "npm run prepare && node ./index.js", "dev": "npm run prepare && pm2 start ./index.js", "debug": "node --inspect-brk ./index.js" }, diff --git a/scripts/pictures_folder_exist.js b/scripts/pictures_folder_exist.js deleted file mode 100644 index 841193a..0000000 --- a/scripts/pictures_folder_exist.js +++ /dev/null @@ -1,17 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -const pictures_folder_path = path.resolve('./pictures'); - -const exist = fs.existsSync(pictures_folder_path); - -if (!exist) { - fs.mkdir(pictures_folder_path, err => { - if (!err) { - console.log('pictures文件夹创建成功'); - } - conso.log('创建pictures文件夹发生错误', err); - }); -} else { - console.log('pictures文件已存在'); -} diff --git a/scripts/prepare.js b/scripts/prepare.js new file mode 100644 index 0000000..38e54be --- /dev/null +++ b/scripts/prepare.js @@ -0,0 +1,28 @@ +const fs = require('fs'); +const path = require('path'); + + +// 判断图片存储文件是否存在 +const pictures_folder_path = path.resolve('./pictures'); +const exist = fs.existsSync(pictures_folder_path); + +if (!exist) { + fs.mkdir(pictures_folder_path, err => { + if (!err) { + console.log('pictures文件夹创建成功'); + } + console.log('创建pictures文件夹发生错误', err); + }); +} else { + console.log('pictures文件已存在'); +} + +// 配置文件写入 +const CONFIG_FILE_PATH = path.resolve('./config.json'); + +const is_config_file_exist = fs.existsSync(CONFIG_FILE_PATH); +if (is_config_file_exist) { + fs.createReadStream(CONFIG_FILE_PATH, {encoding: 'utf8'}).pipe( + fs.createWriteStream(path.resolve('./src/config.json')) + ) +} diff --git a/src/config.json b/src/config.json new file mode 100644 index 0000000..23e56ae --- /dev/null +++ b/src/config.json @@ -0,0 +1,16 @@ +{ + "NOTE_MAP": { + "星辰之主": "http://www.booktxt.net/2_2982/", + "打开你的任务日志": "http://www.biqugev.com/27_27360/", + "诡秘之主": "https://www.biquge.com.tw/19_19485/", + "黑龙法典": "http://www.biquge.com.tw/19_19575/" + }, + "TARGET_MAIL": { + "address": "baihaihui131225@gmail.com" + }, + "SOURCE_MAIL": { + "address": "2911403289@qq.com", + "password": "rtrujefmjqwedfaf", + "host": "smtp.qq.com" + } +} diff --git a/src/constant.js b/src/constant.js index 585b183..0264702 100644 --- a/src/constant.js +++ b/src/constant.js @@ -1,4 +1,4 @@ -// 常量 +const config = require('./config.json'); const path = require('path'); // 图片保存目录 @@ -12,15 +12,15 @@ const NEXT_PICTURE_SUFFIX = 'next'; const PICTURE_TOLERANCE = 0.001; // noteMap 小说的map数据机构。小说名为key,url为value -const NOTE_MAP = { - 星辰之主: 'http://www.booktxt.net/2_2982/', - 打开你的任务日志: 'http://www.biqugev.com/27_27360/', - 诡秘之主: 'https://www.biquge.com.tw/19_19485/', - 黑龙法典: 'http://www.biquge.com.tw/19_19575/' -}; +const NOTE_MAP = config ? config.NOTE_MAP : {}; + +// 邮件信息 +const TARGET_MAIL = config ? config.TARGET_MAIL : {}; +const SOURCE_MAIL = config ? config.SOURCE_MAIL : {} // 定时任务的时间间隔 -const CHECK_INTERVAL = '59 30 * * * *'; +const CHECK_INTERVAL = '41 * * * * *'; + module.exports = { DIR_PATH, @@ -29,5 +29,8 @@ module.exports = { NOTE_MAP, PICTURE_TOLERANCE, CHECK_INTERVAL, + CONFIG_FILE_PATH, + TARGET_MAIL, + SOURCE_MAIL } diff --git a/src/mail.js b/src/mail.js index fb1ee60..867a2cf 100644 --- a/src/mail.js +++ b/src/mail.js @@ -1,4 +1,5 @@ const node_mailer = require('nodemailer'); +const { SOURCE_MAIL, TARGET_MAIL } = require('./constant'); const { log, create_base_error, create_base_info } = require('./log'); @@ -9,8 +10,8 @@ const transport = node_mailer.createTransport({ secure: true, secureConnection: true, auth: { - user: '2911403289@qq.com', - pass: 'hwgpvfyhcsjgdfdj', // qq邮箱授权码,不是密码 + user: SOURCE_MAIL.address, + pass: SOURCE_MAIL.pass, // qq邮箱授权码,不是密码 }, }); @@ -27,12 +28,12 @@ const send_mail = (mail_option, cb) => { const get_mail_option = (target_mail, content ) => { const base_mail_option = { - from: '2911403289@qq.com', + from: SOURCE_MAIL.address, subject: '小说更新推送', }; return Object.assign({}, base_mail_option, { - to: target_mail || 'baihaihui131225@gmail.com', + to: target_mail || TARGET_MAIL.address, ...content }); }; diff --git a/src/picture_utils.js b/src/picture_utils.js index f64ed28..1ebde54 100644 --- a/src/picture_utils.js +++ b/src/picture_utils.js @@ -37,7 +37,7 @@ const compare_picture = (prevPicturePath, nextPicturePath, cb) => { } // 检查picture是不是存在 -const check_picture_exit = picture_url => { +const check_picture_exist = picture_url => { if (!picture_url) return null; return fs.existsSync(picture_url); }; @@ -60,6 +60,6 @@ const rename_picture = (old_picture_url, new_picture_url) => { module.exports = { compare_picture, delete_picture, - check_picture_exit, + check_picture_exist, rename_picture, }; From 6ad79c7851bfe8f6d343dc316ac6039f751a9a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=8F=E6=B5=B7=E8=BE=89?= Date: Sat, 3 Nov 2018 11:53:31 +0800 Subject: [PATCH 05/10] chore: comment --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index b1a6de6..b484910 100644 --- a/config.json +++ b/config.json @@ -10,7 +10,7 @@ }, "SOURCE_MAIL": { "address": "2911403289@qq.com", - "password": "xxxxxx", + "password": "xxxxxx", // 邮箱授权码 "host": "smtp.qq.com" } } From e524c446856aa06ca02dad595d22199ea07024b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=8F=E6=B5=B7=E8=BE=89?= Date: Sat, 3 Nov 2018 12:45:13 +0800 Subject: [PATCH 06/10] bugfix: schedule job --- src/constant.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constant.js b/src/constant.js index 0264702..7ff096d 100644 --- a/src/constant.js +++ b/src/constant.js @@ -19,7 +19,7 @@ const TARGET_MAIL = config ? config.TARGET_MAIL : {}; const SOURCE_MAIL = config ? config.SOURCE_MAIL : {} // 定时任务的时间间隔 -const CHECK_INTERVAL = '41 * * * * *'; +const CHECK_INTERVAL = '41 30 * * * *'; module.exports = { From 7ab1e5ccc4bd8f59d22ef91dee4cf42065a82dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=8F=E6=B5=B7=E8=BE=89?= Date: Sat, 3 Nov 2018 12:46:57 +0800 Subject: [PATCH 07/10] chore: delete unuse config --- src/config.json | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 src/config.json diff --git a/src/config.json b/src/config.json deleted file mode 100644 index 23e56ae..0000000 --- a/src/config.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "NOTE_MAP": { - "星辰之主": "http://www.booktxt.net/2_2982/", - "打开你的任务日志": "http://www.biqugev.com/27_27360/", - "诡秘之主": "https://www.biquge.com.tw/19_19485/", - "黑龙法典": "http://www.biquge.com.tw/19_19575/" - }, - "TARGET_MAIL": { - "address": "baihaihui131225@gmail.com" - }, - "SOURCE_MAIL": { - "address": "2911403289@qq.com", - "password": "rtrujefmjqwedfaf", - "host": "smtp.qq.com" - } -} From 6a111486fc7c7ecd99d86b5c314cf986aef9b0c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=8F=E6=B5=B7=E8=BE=89?= Date: Sat, 3 Nov 2018 14:33:17 +0800 Subject: [PATCH 08/10] =?UTF-8?q?bugfix:=20=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constant.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constant.js b/src/constant.js index 7ff096d..e81797e 100644 --- a/src/constant.js +++ b/src/constant.js @@ -19,7 +19,7 @@ const TARGET_MAIL = config ? config.TARGET_MAIL : {}; const SOURCE_MAIL = config ? config.SOURCE_MAIL : {} // 定时任务的时间间隔 -const CHECK_INTERVAL = '41 30 * * * *'; +const CHECK_INTERVAL = '30 * * * * *'; // 每小时的30分钟 module.exports = { From 849a4ecb39219546f696d214b2fa60679b578915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=8F=E6=B5=B7=E8=BE=89?= Date: Sat, 3 Nov 2018 14:46:55 +0800 Subject: [PATCH 09/10] =?UTF-8?q?bugfix:=20=E5=A4=9A=E4=BD=99=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.json | 2 +- src/constant.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/config.json b/config.json index b484910..3d9ec8a 100644 --- a/config.json +++ b/config.json @@ -10,7 +10,7 @@ }, "SOURCE_MAIL": { "address": "2911403289@qq.com", - "password": "xxxxxx", // 邮箱授权码 + "password": "xxxx", "host": "smtp.qq.com" } } diff --git a/src/constant.js b/src/constant.js index e81797e..0db1929 100644 --- a/src/constant.js +++ b/src/constant.js @@ -29,8 +29,7 @@ module.exports = { NOTE_MAP, PICTURE_TOLERANCE, CHECK_INTERVAL, - CONFIG_FILE_PATH, TARGET_MAIL, SOURCE_MAIL -} +}; From 8991e4b51f5bc574aa9a3ec3219e55cdc07d205f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=8F=E6=B5=B7=E8=BE=89?= Date: Thu, 8 Nov 2018 12:06:45 +0800 Subject: [PATCH 10/10] bugfix: password --- src/mail.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mail.js b/src/mail.js index 867a2cf..8f52d1f 100644 --- a/src/mail.js +++ b/src/mail.js @@ -11,7 +11,7 @@ const transport = node_mailer.createTransport({ secureConnection: true, auth: { user: SOURCE_MAIL.address, - pass: SOURCE_MAIL.pass, // qq邮箱授权码,不是密码 + pass: SOURCE_MAIL.password, // qq邮箱授权码,不是密码 }, });

AltStyle によって変換されたページ (->オリジナル) /