添加仅保存最近latest.json选项
This commit is contained in:
parent
2eca6c3553
commit
fb659eb831
@ -13,4 +13,8 @@ EXECUTE_AT_STARTUP=1
|
|||||||
|
|
||||||
# 数据是否推送到Git仓库
|
# 数据是否推送到Git仓库
|
||||||
# 1为是
|
# 1为是
|
||||||
PUSH_TO_GIT=0
|
PUSH_TO_GIT=0
|
||||||
|
|
||||||
|
# 是否仅保存 latest.json 而不保存其他文件作为存档
|
||||||
|
# 1为是
|
||||||
|
LATEST_DATA_ONLY=0
|
@ -6,6 +6,9 @@ const path = require('path');
|
|||||||
|
|
||||||
const DATA_FOLDER = path.join(path.dirname(__dirname), process.env.DATA_FOLDER ?? 'data');
|
const DATA_FOLDER = path.join(path.dirname(__dirname), process.env.DATA_FOLDER ?? 'data');
|
||||||
console.log("DATA_FOLDER", DATA_FOLDER);
|
console.log("DATA_FOLDER", DATA_FOLDER);
|
||||||
|
createFolder(DATA_FOLDER); // 程序运行就保证 data 目录存在
|
||||||
|
|
||||||
|
const LATEST_DATA_ONLY = process.env.LATEST_DATA_ONLY == true;
|
||||||
|
|
||||||
// 请求微博热搜 APi 接口
|
// 请求微博热搜 APi 接口
|
||||||
async function getApiResult(url) {
|
async function getApiResult(url) {
|
||||||
@ -44,6 +47,7 @@ async function createFolder(folderToCreate) {
|
|||||||
|
|
||||||
// 保存 JSON
|
// 保存 JSON
|
||||||
function saveJSON({ now, fileNameSuffix, object, compress = true, uncompress = true }) {
|
function saveJSON({ now, fileNameSuffix, object, compress = true, uncompress = true }) {
|
||||||
|
if (LATEST_DATA_ONLY) return;
|
||||||
|
|
||||||
let year = now.substring(0, 4);
|
let year = now.substring(0, 4);
|
||||||
let month = now.substring(5, 7);
|
let month = now.substring(5, 7);
|
||||||
|
Loading…
Reference in New Issue
Block a user