From fb659eb8310eece5ba0be5ff617bbabaa9f7ce71 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: Wed, 27 Jul 2022 00:26:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BB=85=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E6=9C=80=E8=BF=91latest.json=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 6 +++++- src/get_hotband.js | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 59caf61..c9a3abd 100644 --- a/.env.example +++ b/.env.example @@ -13,4 +13,8 @@ EXECUTE_AT_STARTUP=1 # 数据是否推送到Git仓库 # 1为是 -PUSH_TO_GIT=0 \ No newline at end of file +PUSH_TO_GIT=0 + +# 是否仅保存 latest.json 而不保存其他文件作为存档 +# 1为是 +LATEST_DATA_ONLY=0 \ No newline at end of file diff --git a/src/get_hotband.js b/src/get_hotband.js index f3caa97..1eec48c 100644 --- a/src/get_hotband.js +++ b/src/get_hotband.js @@ -6,6 +6,9 @@ const path = require('path'); const DATA_FOLDER = path.join(path.dirname(__dirname), process.env.DATA_FOLDER ?? 'data'); console.log("DATA_FOLDER", DATA_FOLDER); +createFolder(DATA_FOLDER); // 程序运行就保证 data 目录存在 + +const LATEST_DATA_ONLY = process.env.LATEST_DATA_ONLY == true; // 请求微博热搜 APi 接口 async function getApiResult(url) { @@ -44,6 +47,7 @@ async function createFolder(folderToCreate) { // 保存 JSON function saveJSON({ now, fileNameSuffix, object, compress = true, uncompress = true }) { + if (LATEST_DATA_ONLY) return; let year = now.substring(0, 4); let month = now.substring(5, 7);