From 434fdf3c67caaf1a5733cd137bb5c40fc99c3552 Mon Sep 17 00:00:00 2001 From: hillerliao Date: Sat, 18 Apr 2020 11:18:10 +0800 Subject: [PATCH] add infoq topic --- rsshub/blueprints/main.py | 6 ++++++ rsshub/spiders/infoq/recommend.py | 2 +- rsshub/spiders/infoq/topic.py | 29 +++++++++++++++++++++++++++++ rsshub/templates/main/feeds.html | 6 +++++- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 rsshub/spiders/infoq/topic.py diff --git a/rsshub/blueprints/main.py b/rsshub/blueprints/main.py index 84cbcea..cb9b34d 100644 --- a/rsshub/blueprints/main.py +++ b/rsshub/blueprints/main.py @@ -60,6 +60,12 @@ def infoq_recommend(): return render_template('main/atom.xml', **filter_content(ctx())) +@bp.route('/infoq/topic/') +def infoq_topic(category=''): + from rsshub.spiders.infoq.topic import ctx + return render_template('main/atom.xml', **filter_content(ctx(category))) + + @bp.route('/dxzg/notice') def dxzg_notice(): from rsshub.spiders.dxzg.notice import ctx diff --git a/rsshub/spiders/infoq/recommend.py b/rsshub/spiders/infoq/recommend.py index 31df65c..865416a 100644 --- a/rsshub/spiders/infoq/recommend.py +++ b/rsshub/spiders/infoq/recommend.py @@ -15,7 +15,7 @@ def parse(post): def ctx(): DEFAULT_HEADERS.update({'Referer': 'https://www.infoq.cn'}) # 必须设置Referer,不然会451错误 import json - posts = requests.post(f'{domain}/public/v1/my/recommond', data={'size': 20}, headers=DEFAULT_HEADERS) + posts = requests.post(f'{domain}/public/v1/my/recommond', json={'size': 20}, headers=DEFAULT_HEADERS) posts = json.loads(posts.text)['data'] return { 'title': 'infoq', diff --git a/rsshub/spiders/infoq/topic.py b/rsshub/spiders/infoq/topic.py new file mode 100644 index 0000000..5aa9d12 --- /dev/null +++ b/rsshub/spiders/infoq/topic.py @@ -0,0 +1,29 @@ +import requests +from rsshub.utils import DEFAULT_HEADERS + +domain = 'https://www.infoq.cn' + + +def parse(post): + item = {} + item['title'] = post['article_title'] + item['description'] = f"{post['article_summary']}
" + item['link'] = f"{domain}/article/{post['uuid']}" + return item + + +def ctx(category=''): + referer = f'{domain}/topic/{category}' + DEFAULT_HEADERS.update({'Referer': referer}) + url = f'{domain}/public/v1/article/getList' + import json + posts = requests.post(url, json={'size': 20, 'id': category, 'type': 0}, headers=DEFAULT_HEADERS) + + posts = json.loads(posts.text)['data'] + return { + 'title': f'{category} - topic - infoq', + 'link': referer, + 'description': 'InfoQ - 促进软件开发领域知识与创新的传播', + '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 ae99559..ff1fb61 100644 --- a/rsshub/templates/main/feeds.html +++ b/rsshub/templates/main/feeds.html @@ -58,9 +58,13 @@

InfoQ

-
推荐内容 by alphardex
+
推荐内容 by alphardex hillerliao

举例:https://pyrsshub.herokuapp.com/infoq/recommend

路由:/infoq/recommend

+ +
主题内容 by hillerliao
+

举例:https://pyrsshub.herokuapp.com/infoq/topic/159

+

路由:/infoq/topic/:category