From 1ee3fc6f325c0aba35da7a69186b76877241fa1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?= <2291200076@qq.com> Date: Sun, 24 Jul 2022 01:57:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20PUSH=5FTO=5FGIT=20?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 6 +++++- index.js | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.env b/.env index 494a7a5..59caf61 100644 --- a/.env +++ b/.env @@ -9,4 +9,8 @@ DATA_FOLDER=data # 是否在程序刚一启动时就抓取一次数据 # 1为是 -EXECUTE_AT_STARTUP=1 \ No newline at end of file +EXECUTE_AT_STARTUP=1 + +# 数据是否推送到Git仓库 +# 1为是 +PUSH_TO_GIT=0 \ No newline at end of file diff --git a/index.js b/index.js index 7692bc9..96881a4 100644 --- a/index.js +++ b/index.js @@ -14,6 +14,7 @@ dotenv.config('./.env'); // 导入 .env 文件中的环境变量 const DEBUG_MODE = process.env.DEBUG_MODE == true; const EXECUTE_AT_STARTUP = process.env.EXECUTE_AT_STARTUP == true; +const PUSH_TO_GIT = process.env.PUSH_TO_GIT == true; const ROOT_PATH = path.join(__dirname, process.env.DATA_FOLDER ?? 'data'); @@ -45,6 +46,12 @@ console.log("Start running ..."); async function start() { // 爬取热搜数据 await get_hotband.main(); + + // 调试模式下 + if (DEBUG_MODE) { + // 推送到 Git 仓库 + await pushToGitRepo(); + } } // 调试模式下,程序一启动就首先运行一次 @@ -63,6 +70,8 @@ const scheduleJob = schedule.scheduleJob('05 * * * * *', start); * 定时将热搜数据推送到 Git 仓库 */ async function pushToGitRepo() { + if (!PUSH_TO_GIT) return; + let commands = [ 'git status', 'git pull',