From 7dc1508458f77b499945eaeaa4c1ed8d3e6db032 Mon Sep 17 00:00:00 2001 From: alphardex <2582347430@qq.com> Date: Fri, 25 Jan 2019 14:59:25 +0800 Subject: [PATCH] add feed - infoq --- rsshub/blueprints/main.py | 6 ++++++ rsshub/spiders/infoq/recommend.py | 24 ++++++++++++++++++++++++ rsshub/templates/main/feeds.html | 9 +++++++++ 3 files changed, 39 insertions(+) create mode 100644 rsshub/spiders/infoq/recommend.py diff --git a/rsshub/blueprints/main.py b/rsshub/blueprints/main.py index 3b5af73..286c040 100644 --- a/rsshub/blueprints/main.py +++ b/rsshub/blueprints/main.py @@ -44,3 +44,9 @@ def chuansongme_articles(category=''): def ctolib_topics(category=''): from rsshub.spiders.ctolib.topics import ctx return render_template('main/atom.xml', **filter_content(ctx(category))) + + +@bp.route('/infoq/recommend') +def infoq_recommend(): + from rsshub.spiders.infoq.recommend import ctx + return render_template('main/atom.xml', **filter_content(ctx())) diff --git a/rsshub/spiders/infoq/recommend.py b/rsshub/spiders/infoq/recommend.py new file mode 100644 index 0000000..b328c21 --- /dev/null +++ b/rsshub/spiders/infoq/recommend.py @@ -0,0 +1,24 @@ +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(): + DEFAULT_HEADERS.update({'Referer': 'https://www.infoq.cn'}) # 必须设置Referer,不然会451错误 + posts = requests.post(f'{domain}/public/v1/my/recommond', data={'size': 20}, headers=DEFAULT_HEADERS).json()['data'] + return { + 'title': 'infoq', + 'link': domain, + 'description': 'InfoQ - 促进软件开发领域知识与创新的传播', + 'author': 'alphardex', + '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 65690bc..24381a0 100644 --- a/rsshub/templates/main/feeds.html +++ b/rsshub/templates/main/feeds.html @@ -55,4 +55,13 @@
+
+
+

InfoQ

+
推荐内容 by alphardex
+

举例:https://rsshub-python.herokuapp.com/infoq/recommend

+

路由:/infoq/recommend

+
+
+
{% endblock content %} \ No newline at end of file