add nhk topic news

This commit is contained in:
hillerliao
2024-01-21 23:44:19 +09:00
parent f921abe399
commit b23fa45575
3 changed files with 47 additions and 0 deletions

View File

@@ -310,6 +310,12 @@ def nhk_newseasy(category='', keywords=''):
from rsshub.spiders.nhk.newseasy import ctx
return render_template('main/atom.xml', **filter_content(ctx(category)))
@bp.route('/nhk/topic/<string:category>')
@cache.cached(timeout=3600)
def nhk_topic(category='', keywords=''):
from rsshub.spiders.nhk.topic import ctx
return render_template('main/atom.xml', **filter_content(ctx(category)))
@bp.route('/tadoku/books/<string:category>')
@cache.cached(timeout=3600)
def tadoku_books(category=''):

View File

@@ -0,0 +1,35 @@
import json
import requests
import arrow
from rsshub.utils import DEFAULT_HEADERS
domain = 'https://www3.nhk.or.jp'
def date_format(pubDate):
date = arrow.get(pubDate, 'ddd, DD MMM YYYY HH:mm:ss Z')
iso = date.isoformat()
return iso
def parse(post):
item = {}
item['title'] = post['title']
item['description'] = post['title']
item['link'] = domain + post['link']
item['pubDate'] = date_format(post['pubDate'])
item['author'] = 'NHK'
return item
def ctx(category=''):
url = f'{domain}/news/json16/word/{category}_001.json?_=1705840617679'
posts = requests.get(url)
word = json.loads(posts.text)['channel']['word']
posts = json.loads(posts.text)['channel']['item']
return {
'title': f'{word} - NHK News',
'link': f'{domain}/news/word/{category}.html',
'description': f'{word}の最新ニュース・特集一覧',
'author': 'hillerliao',
'items': list(map(parse, posts))
}

View File

@@ -49,6 +49,12 @@
<h6 class="text-muted">NHK - Web News Easy <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/nhk/newseasy" target="_blank">https://pyrsshub.vercel.app/nhk/newseasy</a></p>
<p class="card-text">路由:<code>/nhk/newseasy</code></p>
<h6 class="text-muted">NHK - topic news <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/nhk/topic/0001595" target="_blank">https://pyrsshub.vercel.app/nhk/topic/0001595</a></p>
<p class="card-text">路由:<code>/nhk/topic/:category</code></p>
<p class="card-text">参数category, topic id</p>
</div>
</div>
<br>