mirror of
https://github.com/d0zingcat/RSSHub-python.git
synced 2026-06-12 15:10:49 +00:00
add readhub topic
This commit is contained in:
@@ -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/<string:type>/<string:uid>')
|
||||
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/<string:category>')
|
||||
def infoq_profile(category=''):
|
||||
from rsshub.spiders.infoq.profile import ctx
|
||||
|
||||
34
rsshub/spiders/readhub/topic.py
Normal file
34
rsshub/spiders/readhub/topic.py
Normal file
@@ -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))
|
||||
}
|
||||
@@ -188,6 +188,19 @@
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
|
||||
<div class="card text-left">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">Readhub</h4>
|
||||
<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.vercel.app/readhub/topic/10/0acaf84bdef38ea9" target="_blank">https://pyrsshub.vercel.app/readhub/topic/10/0acaf84bdef38ea9</a></p>
|
||||
<p class="card-text">路由:<code>/readhub/topic/:type/:category</code></p>
|
||||
<p class="card-text">参数:type [必填,类型,10 entity(实体) | 22 tag(标签)]</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
|
||||
<div class="card text-left">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">巨潮资讯</h4>
|
||||
|
||||
Reference in New Issue
Block a user