From 9d667e830080c07d0bc232e9e1948917489942c5 Mon Sep 17 00:00:00 2001 From: Zhouzhongping Date: Mon, 26 Feb 2024 16:18:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=EF=BC=9A=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Static/lunar_data.js | 36 ++++++++++++++++++++++++++++++++++++ Templates/日志 - 周记模板.md | 6 +++--- Templates/日志 - 季度模板.md | 6 +++--- Templates/日志 - 日记模板.md | 6 +++--- 4 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 Static/lunar_data.js diff --git a/Static/lunar_data.js b/Static/lunar_data.js new file mode 100644 index 00000000..710f03c9 --- /dev/null +++ b/Static/lunar_data.js @@ -0,0 +1,36 @@ +const https = require("https"); + +/** + * 获取并格式化当前日期的农历信息。 + * @returns {Promise} 返回格式化后的农历信息。 + */ +async function getLunarDate() { + return new Promise((resolve, reject) => { + const url = "https://api.timelessq.com/time"; + + https + .get(url, (resp) => { + let data = ""; + + resp.on("data", (chunk) => { + data += chunk; + }); + + resp.on("end", () => { + const result = JSON.parse(data); + if (result.errno === 0) { + const lunar = result.data.lunar; + const formattedLunarDate = `${lunar.cyclicalYear}${lunar.zodiac}年 ${lunar.cyclicalMonth}月 ${lunar.cyclicalDay}日 农历${lunar.cnMonth}${lunar.cnDay}`; + resolve(formattedLunarDate); + } else { + reject("Failed to fetch lunar date"); + } + }); + }) + .on("error", (err) => { + reject("Error: " + err.message); + }); + }); +} + +module.exports = getLunarDate; diff --git a/Templates/日志 - 周记模板.md b/Templates/日志 - 周记模板.md index f4a82ae5..04596e47 100644 --- a/Templates/日志 - 周记模板.md +++ b/Templates/日志 - 周记模板.md @@ -1,8 +1,8 @@ ## 🗓️ Info -| Date | Weather | Moon | -| -------------- | ------------ | ---- | -| <% tp.date.now("ddd HH:mm") %> | <% tp.user.wttr_weather(" 郑州 ", "units=m&format=%l+%t+%c&lang=zh") %> | <% tp.user.wttr_weather("郑州", "format=%m&lang=zh") %> | +| Date | Lunar | Weather | Moon | +| -------------- | ------------ | ---- | ---- | +| <% tp.date.now("ddd HH:mm") %> | <% tp.user.lunar_data() %> | <% tp.user.wttr_weather(" 郑州 ", "units=m&format=%l+%t+%c&lang=zh") %> | <% tp.user.wttr_weather("郑州", "format=%m&lang=zh") %> | ## 😊 Emotions diff --git a/Templates/日志 - 季度模板.md b/Templates/日志 - 季度模板.md index e4978ee7..9e58bb22 100644 --- a/Templates/日志 - 季度模板.md +++ b/Templates/日志 - 季度模板.md @@ -1,8 +1,8 @@ ## 📆 Info -| Date | Weather | Moon | -| -------------- | ------------ | ---- | -| <% tp.date.now("ddd HH:mm") %> | <% tp.user.wttr_weather("郑州", "units=m&format=%l+%t+%c&lang=zh") %> | <% tp.user.wttr_weather("郑州", "format=%m&lang=zh") %> | +| Date | Lunar | Weather | Moon | +| -------------- | ------------ | ---- | ---- | +| <% tp.date.now("ddd HH:mm") %> | <% tp.user.lunar_data() %> | <% tp.user.wttr_weather("郑州", "units=m&format=%l+%t+%c&lang=zh") %> | <% tp.user.wttr_weather("郑州", "format=%m&lang=zh") %> | ## 🌟 Overview diff --git a/Templates/日志 - 日记模板.md b/Templates/日志 - 日记模板.md index 8bcf8b59..83d3e912 100644 --- a/Templates/日志 - 日记模板.md +++ b/Templates/日志 - 日记模板.md @@ -1,8 +1,8 @@ ## 📅 Info -| Date | Weather | Moon | -| -------------- | ------------ | ---- | -| <% tp.date.now("ddd HH:mm") %> | <% tp.user.wttr_weather("郑州", "units=m&format=%l+%t+%c&lang=zh") %> | <% tp.user.wttr_weather("郑州", "format=%m&lang=zh") %> | +| Date | Lunar | Weather | Moon | +| ------------------------------ | -------------------------- | ------------------------------------------------------------ | ------------------------------------------------------- | +| <% tp.date.now("ddd HH:mm") %> | <% tp.user.lunar_data() %> | <% tp.user.wttr_weather("郑州", "units=m&format=%l+%t+%c&lang=zh") %> | <% tp.user.wttr_weather("郑州", "format=%m&lang=zh") %> | ## 📖 Daily