From f01b87b14fa286bcd39291d227a1f4ade1b251ad Mon Sep 17 00:00:00 2001 From: hillerliao Date: Sun, 16 Oct 2022 18:28:06 +0800 Subject: [PATCH] fetch infoq author article --- rsshub/blueprints/main.py | 4 ++++ rsshub/spiders/infoq/profile.py | 32 ++++++++++++++++++++++++++++++++ rsshub/templates/main/feeds.html | 4 ++++ 3 files changed, 40 insertions(+) create mode 100644 rsshub/spiders/infoq/profile.py diff --git a/rsshub/blueprints/main.py b/rsshub/blueprints/main.py index 8689194..48cc50f 100644 --- a/rsshub/blueprints/main.py +++ b/rsshub/blueprints/main.py @@ -68,6 +68,10 @@ def infoq_topic(category=''): from rsshub.spiders.infoq.topic import ctx return render_template('main/atom.xml', **filter_content(ctx(category))) +@bp.route('/infoq/profile/') +def infoq_profile(category=''): + from rsshub.spiders.infoq.profile import ctx + return render_template('main/atom.xml', **filter_content(ctx(category))) @bp.route('/dxzg/notice') def dxzg_notice(): diff --git a/rsshub/spiders/infoq/profile.py b/rsshub/spiders/infoq/profile.py new file mode 100644 index 0000000..1317365 --- /dev/null +++ b/rsshub/spiders/infoq/profile.py @@ -0,0 +1,32 @@ +import requests +import json +from rsshub.utils import DEFAULT_HEADERS +from rsshub.utils import fetch + +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']}" + item['pubDate'] = post['publish_time'] + return item + + +def ctx(category=''): + referer = f'{domain}/profile/{category}/publish' + DEFAULT_HEADERS.update({'Referer': referer}) + url = f'{domain}/public/v1/user/getListByAuthor' + posts = requests.post(url, json={'size': 12, 'id': category, 'type': 0}, headers=DEFAULT_HEADERS) + tree = fetch(referer,headers=DEFAULT_HEADERS) + feed_title = tree.css('title::text').get() + posts = json.loads(posts.text)['data'] + return { + 'title': f'{feed_title} - Profile - 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 a86a44b..b2774b4 100644 --- a/rsshub/templates/main/feeds.html +++ b/rsshub/templates/main/feeds.html @@ -118,6 +118,10 @@
主题内容 by hillerliao

举例:https://pyrsshub.vercel.app/infoq/topic/159

路由:/infoq/topic/:category

+ +
作者内容by hillerliao
+

举例:https://pyrsshub.vercel.app/infoq/profile/8D1F7C1F2C23FD

+

路由:/infoq/profile/:category