From 1fad4d713765a37f7880fef6b80be2a041b68498 Mon Sep 17 00:00:00 2001 From: xiaoQQya <46475319+xiaoQQya@users.noreply.github.com> Date: Sat, 23 Aug 2025 16:26:11 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E6=97=B6=E9=97=B4=E6=A0=BC=E5=BC=8F=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=AF=BC=E8=87=B4=E6=90=9C=E7=B4=A2=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98=20(#115)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修复资源时间格式解析错误导致搜索失败的问题 * feat: 资源搜索结果显示来源通道 --- app/sdk/cloudsaver.py | 8 +++----- app/sdk/common.py | 15 +++++++++++++++ app/sdk/pansou.py | 17 +++++++++-------- app/templates/index.html | 1 + 4 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 app/sdk/common.py diff --git a/app/sdk/cloudsaver.py b/app/sdk/cloudsaver.py index 2929c02..2eee3aa 100644 --- a/app/sdk/cloudsaver.py +++ b/app/sdk/cloudsaver.py @@ -1,6 +1,6 @@ -from datetime import datetime, timedelta import re import requests +from sdk.common import iso_to_cst class CloudSaver: @@ -128,8 +128,7 @@ class CloudSaver: # 统一发布时间格式 pubdate = item.get("pubDate", "") if pubdate: - utc_tm = datetime.fromisoformat(pubdate) - pubdate = (utc_tm + timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S") + pubdate = iso_to_cst(pubdate) # 链接去重 if link.get("link") not in link_array: link_array.append(link.get("link")) @@ -140,8 +139,7 @@ class CloudSaver: "content": content, "datetime": pubdate, "tags": item.get("tags", []), - "channel": item.get("channel", ""), - "channel_id": item.get("channelId", ""), + "channel": item.get("channelId", ""), "source": "CloudSaver" } ) diff --git a/app/sdk/common.py b/app/sdk/common.py new file mode 100644 index 0000000..068890c --- /dev/null +++ b/app/sdk/common.py @@ -0,0 +1,15 @@ +from datetime import datetime, timezone, timedelta + + +def iso_to_cst(iso_time_str: str) -> str: + """将 ISO 格式的时间字符串转换为 CST(China Standard Time) 时间并格式化为 %Y-%m-%d %H:%M:%S 格式 + + Args: + iso_time_str (str): ISO 格式时间字符串 + + Returns: + str: CST(China Standard Time) 时间字符串 + """ + dt = datetime.fromisoformat(iso_time_str) + dt_cst = dt.astimezone(timezone(timedelta(hours=8))) + return dt_cst.strftime("%Y-%m-%d %H:%M:%S") if dt_cst.year >= 1970 else "" diff --git a/app/sdk/pansou.py b/app/sdk/pansou.py index 5b0447f..5c30893 100644 --- a/app/sdk/pansou.py +++ b/app/sdk/pansou.py @@ -1,8 +1,9 @@ import re -from datetime import datetime, timedelta import requests +from sdk.common import iso_to_cst + class PanSou: """ @@ -55,13 +56,12 @@ class PanSou: ) format_results = [] link_array = [] - for channel in search_results: - url = channel.get("url", "") - note = channel.get("note", "") - tm = channel.get("datetime", "") + for item in search_results: + url = item.get("url", "") + note = item.get("note", "") + tm = item.get("datetime", "") if tm: - utc_tm = datetime.strptime(tm, "%Y-%m-%dT%H:%M:%SZ") - tm = (utc_tm + timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S") + tm = iso_to_cst(tm) match = re.search(pattern, note) if match: @@ -74,10 +74,11 @@ class PanSou: if url != "" and url not in link_array: link_array.append(url) format_results.append({ + "shareurl": url, "taskname": title, "content": content, - "shareurl": url, "datetime": tm, + "channel": item.get("source", ""), "source": "PanSou" }) diff --git a/app/templates/index.html b/app/templates/index.html index a4db29c..a735fcd 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -303,6 +303,7 @@ {{ suggestion.shareurl }} {{ suggestion.source || "网络公开" }} + {{ suggestion.channel }} {{ suggestion.datetime }}