🐛 修复资源时间格式解析错误导致搜索失败的问题 (#115)
Some checks failed
Docker Publish / build-and-push (push) Has been cancelled

* fix: 修复资源时间格式解析错误导致搜索失败的问题
* feat: 资源搜索结果显示来源通道
This commit is contained in:
xiaoQQya 2025-08-23 16:26:11 +08:00 committed by GitHub
parent 6f9b009194
commit 1fad4d7137
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 13 deletions

View File

@ -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"
}
)

15
app/sdk/common.py Normal file
View File

@ -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 ""

View File

@ -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"
})

View File

@ -303,6 +303,7 @@
<a :href="suggestion.shareurl" target="_blank" @click.stop>{{ suggestion.shareurl }}</a>
</small>
<span class="badge bg-transparent border border-success text-success">{{ suggestion.source || "网络公开" }}</span>
<span class="badge bg-transparent border border-info text-info">{{ suggestion.channel }}</span>
<span v-if="suggestion.datetime" class="badge bg-transparent border border-dark text-dark">{{ suggestion.datetime }}</span>
</div>
</div>