mirror of
https://github.com/Cp0204/quark-auto-save.git
synced 2026-01-12 07:10:44 +08:00
🐛 修复资源时间格式解析错误导致搜索失败的问题 (#115)
Some checks failed
Docker Publish / build-and-push (push) Has been cancelled
Some checks failed
Docker Publish / build-and-push (push) Has been cancelled
* fix: 修复资源时间格式解析错误导致搜索失败的问题 * feat: 资源搜索结果显示来源通道
This commit is contained in:
parent
6f9b009194
commit
1fad4d7137
@ -1,6 +1,6 @@
|
|||||||
from datetime import datetime, timedelta
|
|
||||||
import re
|
import re
|
||||||
import requests
|
import requests
|
||||||
|
from sdk.common import iso_to_cst
|
||||||
|
|
||||||
|
|
||||||
class CloudSaver:
|
class CloudSaver:
|
||||||
@ -128,8 +128,7 @@ class CloudSaver:
|
|||||||
# 统一发布时间格式
|
# 统一发布时间格式
|
||||||
pubdate = item.get("pubDate", "")
|
pubdate = item.get("pubDate", "")
|
||||||
if pubdate:
|
if pubdate:
|
||||||
utc_tm = datetime.fromisoformat(pubdate)
|
pubdate = iso_to_cst(pubdate)
|
||||||
pubdate = (utc_tm + timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S")
|
|
||||||
# 链接去重
|
# 链接去重
|
||||||
if link.get("link") not in link_array:
|
if link.get("link") not in link_array:
|
||||||
link_array.append(link.get("link"))
|
link_array.append(link.get("link"))
|
||||||
@ -140,8 +139,7 @@ class CloudSaver:
|
|||||||
"content": content,
|
"content": content,
|
||||||
"datetime": pubdate,
|
"datetime": pubdate,
|
||||||
"tags": item.get("tags", []),
|
"tags": item.get("tags", []),
|
||||||
"channel": item.get("channel", ""),
|
"channel": item.get("channelId", ""),
|
||||||
"channel_id": item.get("channelId", ""),
|
|
||||||
"source": "CloudSaver"
|
"source": "CloudSaver"
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
15
app/sdk/common.py
Normal file
15
app/sdk/common.py
Normal 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 ""
|
||||||
@ -1,8 +1,9 @@
|
|||||||
import re
|
import re
|
||||||
from datetime import datetime, timedelta
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from sdk.common import iso_to_cst
|
||||||
|
|
||||||
|
|
||||||
class PanSou:
|
class PanSou:
|
||||||
"""
|
"""
|
||||||
@ -55,13 +56,12 @@ class PanSou:
|
|||||||
)
|
)
|
||||||
format_results = []
|
format_results = []
|
||||||
link_array = []
|
link_array = []
|
||||||
for channel in search_results:
|
for item in search_results:
|
||||||
url = channel.get("url", "")
|
url = item.get("url", "")
|
||||||
note = channel.get("note", "")
|
note = item.get("note", "")
|
||||||
tm = channel.get("datetime", "")
|
tm = item.get("datetime", "")
|
||||||
if tm:
|
if tm:
|
||||||
utc_tm = datetime.strptime(tm, "%Y-%m-%dT%H:%M:%SZ")
|
tm = iso_to_cst(tm)
|
||||||
tm = (utc_tm + timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S")
|
|
||||||
|
|
||||||
match = re.search(pattern, note)
|
match = re.search(pattern, note)
|
||||||
if match:
|
if match:
|
||||||
@ -74,10 +74,11 @@ class PanSou:
|
|||||||
if url != "" and url not in link_array:
|
if url != "" and url not in link_array:
|
||||||
link_array.append(url)
|
link_array.append(url)
|
||||||
format_results.append({
|
format_results.append({
|
||||||
|
"shareurl": url,
|
||||||
"taskname": title,
|
"taskname": title,
|
||||||
"content": content,
|
"content": content,
|
||||||
"shareurl": url,
|
|
||||||
"datetime": tm,
|
"datetime": tm,
|
||||||
|
"channel": item.get("source", ""),
|
||||||
"source": "PanSou"
|
"source": "PanSou"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -303,6 +303,7 @@
|
|||||||
<a :href="suggestion.shareurl" target="_blank" @click.stop>{{ suggestion.shareurl }}</a>
|
<a :href="suggestion.shareurl" target="_blank" @click.stop>{{ suggestion.shareurl }}</a>
|
||||||
</small>
|
</small>
|
||||||
<span class="badge bg-transparent border border-success text-success">{{ suggestion.source || "网络公开" }}</span>
|
<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>
|
<span v-if="suggestion.datetime" class="badge bg-transparent border border-dark text-dark">{{ suggestion.datetime }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user