diff --git a/.env.example b/hotband/.env.example similarity index 91% rename from .env.example rename to hotband/.env.example index c9a3abd..4fb6064 100644 --- a/.env.example +++ b/hotband/.env.example @@ -1,20 +1,20 @@ -# 调试模式 -# 1为开启调试 -DEBUG_MODE=1 - -# 爬取数据保存的文件夹 -# 目录开头与结尾的 [./] [/] [\] [\\] 均可带可不带 -# 默认为 data 文件夹 -DATA_FOLDER=data - -# 是否在程序刚一启动时就抓取一次数据 -# 1为是 -EXECUTE_AT_STARTUP=1 - -# 数据是否推送到Git仓库 -# 1为是 -PUSH_TO_GIT=0 - -# 是否仅保存 latest.json 而不保存其他文件作为存档 -# 1为是 +# 调试模式 +# 1为开启调试 +DEBUG_MODE=1 + +# 爬取数据保存的文件夹 +# 目录开头与结尾的 [./] [/] [\] [\\] 均可带可不带 +# 默认为 data 文件夹 +DATA_FOLDER=data + +# 是否在程序刚一启动时就抓取一次数据 +# 1为是 +EXECUTE_AT_STARTUP=1 + +# 数据是否推送到Git仓库 +# 1为是 +PUSH_TO_GIT=0 + +# 是否仅保存 latest.json 而不保存其他文件作为存档 +# 1为是 LATEST_DATA_ONLY=0 \ No newline at end of file diff --git a/.gitignore b/hotband/.gitignore similarity index 88% rename from .gitignore rename to hotband/.gitignore index 9fc2270..7467e49 100644 --- a/.gitignore +++ b/hotband/.gitignore @@ -1,8 +1,8 @@ -.DS_Store - -data/* -.env -node_modules -.VSCodeCounter - -test.js +.DS_Store + +data/* +.env +node_modules +.VSCodeCounter + +test.js diff --git a/README.md b/hotband/README.md similarity index 100% rename from README.md rename to hotband/README.md diff --git a/html/assets/css/main.css b/hotband/html/assets/css/main.css similarity index 100% rename from html/assets/css/main.css rename to hotband/html/assets/css/main.css diff --git a/html/assets/image/bilibili.svg b/hotband/html/assets/image/bilibili.svg similarity index 100% rename from html/assets/image/bilibili.svg rename to hotband/html/assets/image/bilibili.svg diff --git a/html/assets/image/icon_rank.png b/hotband/html/assets/image/icon_rank.png similarity index 100% rename from html/assets/image/icon_rank.png rename to hotband/html/assets/image/icon_rank.png diff --git a/html/assets/image/weibo.svg b/hotband/html/assets/image/weibo.svg similarity index 100% rename from html/assets/image/weibo.svg rename to hotband/html/assets/image/weibo.svg diff --git a/html/assets/js/isMobile.js b/hotband/html/assets/js/isMobile.js similarity index 100% rename from html/assets/js/isMobile.js rename to hotband/html/assets/js/isMobile.js diff --git a/html/bilibili_hotband.html b/hotband/html/bilibili_hotband.html similarity index 100% rename from html/bilibili_hotband.html rename to hotband/html/bilibili_hotband.html diff --git a/html/bilibili_rank.html b/hotband/html/bilibili_rank.html similarity index 100% rename from html/bilibili_rank.html rename to hotband/html/bilibili_rank.html diff --git a/html/weibo_hotband.html b/hotband/html/weibo_hotband.html similarity index 100% rename from html/weibo_hotband.html rename to hotband/html/weibo_hotband.html diff --git a/index.html b/hotband/index.html similarity index 100% rename from index.html rename to hotband/index.html diff --git a/index.js b/hotband/index.js similarity index 100% rename from index.js rename to hotband/index.js diff --git a/nodemon.json b/hotband/nodemon.json similarity index 93% rename from nodemon.json rename to hotband/nodemon.json index 4878d76..e4e9978 100644 --- a/nodemon.json +++ b/hotband/nodemon.json @@ -1,8 +1,8 @@ -{ - "ignore": [ - ".git", - ".svn", - "node_modules/**/node_modules" - ], - "ext": "js" +{ + "ignore": [ + ".git", + ".svn", + "node_modules/**/node_modules" + ], + "ext": "js" } \ No newline at end of file diff --git a/pack.bat b/hotband/pack.bat similarity index 100% rename from pack.bat rename to hotband/pack.bat diff --git a/pm2 restart.bat b/hotband/pm2 restart.bat similarity index 100% rename from pm2 restart.bat rename to hotband/pm2 restart.bat diff --git a/pm2 restart.sh b/hotband/pm2 restart.sh similarity index 100% rename from pm2 restart.sh rename to hotband/pm2 restart.sh diff --git a/pm2 start.bat b/hotband/pm2 start.bat similarity index 100% rename from pm2 start.bat rename to hotband/pm2 start.bat diff --git a/pm2 start.sh b/hotband/pm2 start.sh similarity index 100% rename from pm2 start.sh rename to hotband/pm2 start.sh diff --git a/hotband/pm2 stop.bat b/hotband/pm2 stop.bat new file mode 100644 index 0000000..b0189d9 --- /dev/null +++ b/hotband/pm2 stop.bat @@ -0,0 +1,2 @@ +pm2 stop weibo-hotband-bot +pm2 delete weibo-hotband-bot \ No newline at end of file diff --git a/hotband/pm2 stop.sh b/hotband/pm2 stop.sh new file mode 100644 index 0000000..b0189d9 --- /dev/null +++ b/hotband/pm2 stop.sh @@ -0,0 +1,2 @@ +pm2 stop weibo-hotband-bot +pm2 delete weibo-hotband-bot \ No newline at end of file diff --git a/src/execute_command.js b/hotband/src/execute_command.js similarity index 97% rename from src/execute_command.js rename to hotband/src/execute_command.js index df21067..d73a6bd 100644 --- a/src/execute_command.js +++ b/hotband/src/execute_command.js @@ -1,40 +1,40 @@ -'use strict'; - -const child_process = require('child_process'); -const iconv = require("iconv-lite"); - -const encoding = "cp936"; -const bufferEncoding = "binary"; - -async function execute(rootPath, cmds) { - let outputs = []; - for (let cmd of cmds) { - let result = await new Promise(function (resolve) { - // refer: https://www.webhek.com/post/execute-a-command-line-binary-with-node-js/ - child_process.exec(cmd, { - cwd: rootPath, // 脚本执行目录 - encoding: bufferEncoding - }, function (err, stdout, stderr) { - if (err) { - resolve({ - cmd: cmd, - err: err, - // err_stack: iconv.decode(Buffer.from(err.stack, bufferEncoding), encoding), - // err_message: iconv.decode(Buffer.from(err.message, bufferEncoding), encoding), - }); - } else { - // 获取命令执行的输出 - resolve({ - cmd: cmd, - stdout: iconv.decode(Buffer.from(stdout, bufferEncoding), encoding), - stderr: iconv.decode(Buffer.from(stderr, bufferEncoding), encoding), - }); - } - }); - }); - outputs.push(result); - } - return outputs; -} - -exports.execute = execute; +'use strict'; + +const child_process = require('child_process'); +const iconv = require("iconv-lite"); + +const encoding = "cp936"; +const bufferEncoding = "binary"; + +async function execute(rootPath, cmds) { + let outputs = []; + for (let cmd of cmds) { + let result = await new Promise(function (resolve) { + // refer: https://www.webhek.com/post/execute-a-command-line-binary-with-node-js/ + child_process.exec(cmd, { + cwd: rootPath, // 脚本执行目录 + encoding: bufferEncoding + }, function (err, stdout, stderr) { + if (err) { + resolve({ + cmd: cmd, + err: err, + // err_stack: iconv.decode(Buffer.from(err.stack, bufferEncoding), encoding), + // err_message: iconv.decode(Buffer.from(err.message, bufferEncoding), encoding), + }); + } else { + // 获取命令执行的输出 + resolve({ + cmd: cmd, + stdout: iconv.decode(Buffer.from(stdout, bufferEncoding), encoding), + stderr: iconv.decode(Buffer.from(stderr, bufferEncoding), encoding), + }); + } + }); + }); + outputs.push(result); + } + return outputs; +} + +exports.execute = execute; diff --git a/src/get_bilibili_hotband.js b/hotband/src/get_bilibili_hotband.js similarity index 100% rename from src/get_bilibili_hotband.js rename to hotband/src/get_bilibili_hotband.js diff --git a/src/get_bilibili_rank.js b/hotband/src/get_bilibili_rank.js similarity index 100% rename from src/get_bilibili_rank.js rename to hotband/src/get_bilibili_rank.js diff --git a/src/get_weibo_hotband.js b/hotband/src/get_weibo_hotband.js similarity index 100% rename from src/get_weibo_hotband.js rename to hotband/src/get_weibo_hotband.js diff --git a/src/utils/fileUtils.js b/hotband/src/utils/fileUtils.js similarity index 100% rename from src/utils/fileUtils.js rename to hotband/src/utils/fileUtils.js diff --git a/src/utils/requestUtils.js b/hotband/src/utils/requestUtils.js similarity index 100% rename from src/utils/requestUtils.js rename to hotband/src/utils/requestUtils.js diff --git a/pm2 stop.bat b/pm2 stop.bat deleted file mode 100644 index b3c0f7f..0000000 --- a/pm2 stop.bat +++ /dev/null @@ -1,2 +0,0 @@ -pm2 stop weibo-hotband-bot -pm2 delete weibo-hotband-bot \ No newline at end of file diff --git a/pm2 stop.sh b/pm2 stop.sh deleted file mode 100644 index b3c0f7f..0000000 --- a/pm2 stop.sh +++ /dev/null @@ -1,2 +0,0 @@ -pm2 stop weibo-hotband-bot -pm2 delete weibo-hotband-bot \ No newline at end of file