mirror of
https://github.com/d0zingcat/RSSHub-python.git
synced 2026-05-18 07:26:48 +00:00
check author node before assigned
This commit is contained in:
@@ -10,25 +10,23 @@ def parse(post):
|
|||||||
item['description'] = post.summary
|
item['description'] = post.summary
|
||||||
item['pubDate'] = post.published
|
item['pubDate'] = post.published
|
||||||
item['link'] = post.link
|
item['link'] = post.link
|
||||||
|
item['author'] = post.author if post.has_key('author') else ''
|
||||||
return item
|
return item
|
||||||
|
|
||||||
def ctx(feed_url=''):
|
def ctx(feed_url=''):
|
||||||
# tree = fetch(feed_url,headers=DEFAULT_HEADERS)
|
res = requests.get(feed_url,headers=DEFAULT_HEADERS)
|
||||||
# title = tree.css('channel').css('title::text').get()
|
feed = feedparser.parse(res.text)
|
||||||
# description = tree.css('channel').css('description').get()
|
|
||||||
# posts = tree.css('item')
|
|
||||||
|
|
||||||
feed = feedparser.parse(feed_url)
|
|
||||||
|
|
||||||
title = feed.feed.title
|
title = feed.feed.title
|
||||||
description = feed.feed.subtitle
|
description = feed.feed.subtitle
|
||||||
|
author = feed.feed.author if feed.feed.has_key('author') \
|
||||||
|
else feed.feed.generator if feed.feed.has_key('generator') \
|
||||||
|
else title
|
||||||
posts = feed.entries
|
posts = feed.entries
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'title': title,
|
'title': title,
|
||||||
'link': feed_url,
|
'link': feed_url,
|
||||||
'description': description,
|
'description': description,
|
||||||
'author': feed.feed.author,
|
'author': author,
|
||||||
'items': list(map(parse, posts))
|
'items': list(map(parse, posts))
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
<entry>
|
<entry>
|
||||||
<id>{{item.link}}</id>
|
<id>{{item.link}}</id>
|
||||||
<title><![CDATA[{{item.title|safe}}]]></title>
|
<title><![CDATA[{{item.title|safe}}]]></title>
|
||||||
|
<author><![CDATA[{{item.author|safe}}]]></author>
|
||||||
<published>{{item.pubDate|default(now)}}</published>
|
<published>{{item.pubDate|default(now)}}</published>
|
||||||
<updated>{{item.pubDate|default(now)}}</updated>
|
<updated>{{item.pubDate|default(now)}}</updated>
|
||||||
<link href="{{item.link}}"/>
|
<link href="{{item.link}}"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user