Skip to content

Commit baa817d

Browse files
committed
优化过滤信息输出, 添加来源和网页链接
1 parent b8537b6 commit baa817d

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

QBRssManager.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,24 @@ def load_type_hints(self, row):
411411
self.text_browser.append('通过api获取feed')
412412
rss_feeds = qb_client.rss_items(include_feed_data=True)
413413
article_titles = []
414+
article_details = []
414415
for x in rss_feeds:
415416
if rss_feeds[x]['url'] in feed_list:
416417
for article in rss_feeds[x]['articles']:
418+
url = ''
419+
# feed的链接, 有点在url里面, 有的在link里面
420+
if 'url' in article:
421+
url = article['url']
422+
elif 'link' in article:
423+
url = article['link']
417424
article_titles.append(article['title'])
425+
article_details.append({
426+
'title': article['title'],
427+
'url': url,
428+
'source_name': x,
429+
})
418430
self.tableWidget.type_hints = article_titles
431+
self.tableWidget.article_details = article_details
419432
# 数据太多可能会导致卡顿 这里尽量不要输出
420433
# logger.info(self.tableWidget.type_hints)
421434
return True

ui/custom_qtext_browser.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,45 @@
1+
from PyQt5.QtCore import QUrl
2+
from PyQt5.QtGui import QDesktopServices
13
from PyQt5.QtWidgets import QTextBrowser
24

35
import g
46
from utils.string_util import wildcard_match_check
57

68

9+
def handle_links(url):
10+
if not url.scheme():
11+
url = QUrl.fromLocalFile(url.toString())
12+
QDesktopServices.openUrl(url)
13+
14+
715
class CustomQTextBrowser(QTextBrowser):
816

917
def __init__(self, parent_app):
1018
super().__init__(parent_app)
1119
self.parent_app = parent_app
1220

21+
# 设置使用外部程序打开链接
22+
self.setOpenLinks(False)
23+
self.anchorClicked.connect(handle_links)
24+
1325
def filter_type_hint(self):
1426
# 过滤输入提示
1527
include_text = g.data_list[self.parent_app.tableWidget.currentItem().row()][2]
1628
exclude_text = g.data_list[self.parent_app.tableWidget.currentItem().row()][3]
1729
type_hints = self.parent_app.tableWidget.type_hints
30+
article_details = self.parent_app.tableWidget.article_details
1831
# 清空
1932
self.parent_app.text_browser.clear()
2033
if include_text.strip() == '' and exclude_text.strip() == '':
2134
# 特殊处理 为空则匹配所有
22-
self.parent_app.text_browser.append('\n'.join(type_hints))
35+
# self.parent_app.text_browser.append('<br/>'.join(type_hints))
36+
for x in article_details:
37+
self.parent_app.text_browser.append(
38+
f"""<a style="color:#00a3a3">{x['source_name']}</a> {x['title']} <a href="{x['url']} alt="{x['url']}"">链接</a>""")
2339
else:
2440
# 保留匹配的
2541
filtered_hints = []
26-
for type_hint in type_hints:
42+
for i, type_hint in enumerate(type_hints):
2743
# 包含关键字
2844
flag1 = False
2945
# 不包含关键字
@@ -35,8 +51,13 @@ def filter_type_hint(self):
3551
# flag2 = all(x.lower() in type_hint.lower() for x in exclude_text.split(' '))
3652
flag2 = wildcard_match_check(type_hint, exclude_text)
3753
if flag1 and not flag2:
38-
filtered_hints.append(type_hint)
54+
# filtered_hints.append(type_hint)
55+
filtered_hints.append(i)
3956
if filtered_hints:
40-
self.parent_app.text_browser.append('\n'.join(filtered_hints))
57+
for i in filtered_hints:
58+
x = article_details[i]
59+
self.parent_app.text_browser.append(
60+
f"""<a style="color:#00a3a3">{x['source_name']}</a> {x['title']} <a href="{x['url']}" alt="{x['url']}">链接</a>""")
61+
4162
else:
42-
self.parent_app.text_browser.append('暂时没有找到相关的feed')
63+
self.parent_app.text_browser.append('<p>暂时没有找到相关的feed</p>')

0 commit comments

Comments
 (0)