add infoq topic

This commit is contained in:
hillerliao
2020-04-18 11:18:10 +08:00
parent 24a4b8f0dd
commit 434fdf3c67
4 changed files with 41 additions and 2 deletions

View File

@@ -60,6 +60,12 @@ def infoq_recommend():
return render_template('main/atom.xml', **filter_content(ctx()))
@bp.route('/infoq/topic/<int:category>')
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

View File

@@ -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',

View File

@@ -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']}<br><img referrerpolicy='no-referrer' src={post.get('article_cover')}>"
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))
}

View File

@@ -58,9 +58,13 @@
<div class="card text-left">
<div class="card-body">
<h4 class="card-title">InfoQ</h4>
<h6 class="text-muted">推荐内容 <a href="https://github.com/alphardex" target="_blank" class="badge badge-secondary">by alphardex</a></h6>
<h6 class="text-muted">推荐内容 <a href="https://github.com/alphardex" target="_blank" class="badge badge-secondary">by alphardex hillerliao</a></h6>
<p class="card-text">举例:<a href="https://pyrsshub.herokuapp.com/infoq/recommend" target="_blank">https://pyrsshub.herokuapp.com/infoq/recommend</a></p>
<p class="card-text">路由:<code>/infoq/recommend</code></p>
<h6 class="text-muted">主题内容 <a href="https://github.com/hillerliao" target="_blank" class="badge badge-secondary">by hillerliao</a></h6>
<p class="card-text">举例:<a href="https://pyrsshub.herokuapp.com/infoq/topic/159" target="_blank">https://pyrsshub.herokuapp.com/infoq/topic/159</a></p>
<p class="card-text">路由:<code>/infoq/topic/:category</code></p>
</div>
</div>
<br>