From 621d974b219c5452a9bd83ac0809465884d4a870 Mon Sep 17 00:00:00 2001 From: Hiller Liao Date: Sun, 29 Dec 2024 23:16:34 +0800 Subject: [PATCH] add readhub topic --- rsshub/blueprints/main.py | 5 +++++ rsshub/spiders/readhub/topic.py | 34 ++++++++++++++++++++++++++++++++ rsshub/templates/main/feeds.html | 13 ++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 rsshub/spiders/readhub/topic.py diff --git a/rsshub/blueprints/main.py b/rsshub/blueprints/main.py index 9ecb97f..0f47f5a 100644 --- a/rsshub/blueprints/main.py +++ b/rsshub/blueprints/main.py @@ -92,6 +92,11 @@ def infoq_topic(category=''): from rsshub.spiders.infoq.topic import ctx return render_template('main/atom.xml', **filter_content(ctx(category))) +@bp.route('/readhub/topic//') +def readhub_topic(type='', uid=''): + from rsshub.spiders.readhub.topic import ctx + return render_template('main/atom.xml', **filter_content(ctx(type,uid))) + @bp.route('/infoq/profile/') def infoq_profile(category=''): from rsshub.spiders.infoq.profile import ctx diff --git a/rsshub/spiders/readhub/topic.py b/rsshub/spiders/readhub/topic.py new file mode 100644 index 0000000..32b7ce0 --- /dev/null +++ b/rsshub/spiders/readhub/topic.py @@ -0,0 +1,34 @@ +import requests +import json +from rsshub.utils import DEFAULT_HEADERS + +domain = 'https://readhub.cn' +api_domain = 'https://api.readhub.cn' + + +def parse(post): + item = {} + item['title'] = post['title'] + item['description'] = post['summary'] + item['link'] = f"{domain}/topic/{post['uid']}" + item['author'] = post['siteNameDisplay'] + item['pubDate'] = post['publishDate'] + return item + + +def ctx(type='', uid=''): + referer = f'{domain}/entity_topics?type=22&uid={uid}&tb=0' + DEFAULT_HEADERS.update({'Referer': referer}) + type_name = 'entity' if type == '10' else 'tag' + url = f'{api_domain}/topic/list_pro?{type_name}_id={uid}&size=10' + posts = requests.get(url, headers=DEFAULT_HEADERS) + topic_name = json.loads(posts.text)['data']['self'][f'{type_name}List'][0]['name'] + + posts = json.loads(posts.text)['data']['items'] + return { + 'title': f'{topic_name} - 主题 - Readhub', + 'link': referer, + 'description': f'"{topic_name}"动态', + 'author': 'hillerliao', + 'items': list(map(parse, posts)) + } \ No newline at end of file diff --git a/rsshub/templates/main/feeds.html b/rsshub/templates/main/feeds.html index 820a65d..14f4463 100644 --- a/rsshub/templates/main/feeds.html +++ b/rsshub/templates/main/feeds.html @@ -188,6 +188,19 @@
+ +
+
+

Readhub

+
主题内容 by hillerliao
+

举例:https://pyrsshub.vercel.app/readhub/topic/10/0acaf84bdef38ea9

+

路由:/readhub/topic/:type/:category

+

参数:type [必填,类型,10 entity(实体) | 22 tag(标签)]

+ +
+
+
+

巨潮资讯