1
0
Code Issues Pull Requests Projects Releases Wiki Activity GitHub Gitee

添加 PUSH_TO_GIT 环境变量

This commit is contained in:
程序员小墨 2022-07-24 01:57:10 +08:00
parent e588e463d5
commit 1ee3fc6f32
2 changed files with 14 additions and 1 deletions

4
.env
View File

@ -10,3 +10,7 @@ DATA_FOLDER=data
# 是否在程序刚一启动时就抓取一次数据 # 是否在程序刚一启动时就抓取一次数据
# 1为是 # 1为是
EXECUTE_AT_STARTUP=1 EXECUTE_AT_STARTUP=1
# 数据是否推送到Git仓库
# 1为是
PUSH_TO_GIT=0

View File

@ -14,6 +14,7 @@ dotenv.config('./.env'); // 导入 .env 文件中的环境变量
const DEBUG_MODE = process.env.DEBUG_MODE == true; const DEBUG_MODE = process.env.DEBUG_MODE == true;
const EXECUTE_AT_STARTUP = process.env.EXECUTE_AT_STARTUP == 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'); const ROOT_PATH = path.join(__dirname, process.env.DATA_FOLDER ?? 'data');
@ -45,6 +46,12 @@ console.log("Start running ...");
async function start() { async function start() {
// 爬取热搜数据 // 爬取热搜数据
await get_hotband.main(); await get_hotband.main();
// 调试模式下
if (DEBUG_MODE) {
// 推送到 Git 仓库
await pushToGitRepo();
}
} }
// 调试模式下,程序一启动就首先运行一次 // 调试模式下,程序一启动就首先运行一次
@ -63,6 +70,8 @@ const scheduleJob = schedule.scheduleJob('05 * * * * *', start);
* 定时将热搜数据推送到 Git 仓库 * 定时将热搜数据推送到 Git 仓库
*/ */
async function pushToGitRepo() { async function pushToGitRepo() {
if (!PUSH_TO_GIT) return;
let commands = [ let commands = [
'git status', 'git status',
'git pull', 'git pull',