forked from platypush/platypush
Merge pull request 'Add author and tags attributes to RSS feed entries' (#238) from 236-add-author-and-tags-columns-to-feeds into master
Reviewed-on: platypush/platypush#238
This commit is contained in:
commit
3279a6ca53
4 changed files with 54 additions and 25 deletions
|
@ -1,5 +1,5 @@
|
|||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from typing import Iterable, Optional
|
||||
|
||||
from platypush.message.event import Event
|
||||
|
||||
|
@ -10,11 +10,30 @@ class NewFeedEntryEvent(Event):
|
|||
"""
|
||||
|
||||
def __init__(
|
||||
self, *, feed_url: str, url: str, title: Optional[str] = None, id: Optional[str] = None,
|
||||
feed_title: Optional[str] = None, published: Optional[datetime] = None, summary: Optional[str] = None,
|
||||
content: Optional[str] = None, **kwargs
|
||||
self,
|
||||
*,
|
||||
feed_url: str,
|
||||
url: str,
|
||||
title: Optional[str] = None,
|
||||
id: Optional[str] = None,
|
||||
feed_title: Optional[str] = None,
|
||||
published: Optional[datetime] = None,
|
||||
summary: Optional[str] = None,
|
||||
content: Optional[str] = None,
|
||||
author: Optional[str] = None,
|
||||
tags: Optional[Iterable[str]] = None,
|
||||
**kwargs
|
||||
):
|
||||
super().__init__(
|
||||
feed_url=feed_url, url=url, title=title, id=id, feed_title=feed_title,
|
||||
published=published, summary=summary, content=content, **kwargs
|
||||
feed_url=feed_url,
|
||||
url=url,
|
||||
title=title,
|
||||
id=id,
|
||||
feed_title=feed_title,
|
||||
published=published,
|
||||
summary=summary,
|
||||
content=content,
|
||||
author=author,
|
||||
tags=tags or [],
|
||||
**kwargs
|
||||
)
|
||||
|
|
|
@ -129,6 +129,12 @@ class RssPlugin(RunnablePlugin):
|
|||
'title': entry.title,
|
||||
'summary': getattr(entry, 'summary', None),
|
||||
'content': self._parse_content(entry),
|
||||
'author': getattr(entry, 'author', None),
|
||||
'tags': [
|
||||
tag['term']
|
||||
for tag in getattr(entry, 'tags', [])
|
||||
if tag.get('term')
|
||||
],
|
||||
}
|
||||
for entry in feed.entries
|
||||
if getattr(entry, 'published_parsed', None)
|
||||
|
|
|
@ -5,36 +5,40 @@ from platypush.schemas import DateTime
|
|||
|
||||
|
||||
class RssFeedEntrySchema(Schema):
|
||||
feed_title = fields.String(metadata=dict(description='Feed title'))
|
||||
feed_title = fields.String(metadata={'description': 'Feed title'})
|
||||
feed_url = fields.URL(
|
||||
required=True,
|
||||
metadata=dict(
|
||||
description='URL of the feed',
|
||||
example='https://some-website/rss',
|
||||
)
|
||||
metadata={
|
||||
'description': 'URL of the feed',
|
||||
'example': 'https://some-website/rss',
|
||||
},
|
||||
)
|
||||
|
||||
id = fields.String(
|
||||
required=True,
|
||||
metadata=dict(
|
||||
description='Feed entry ID',
|
||||
example='1234',
|
||||
)
|
||||
metadata={
|
||||
'description': 'Feed entry ID',
|
||||
'example': '1234',
|
||||
},
|
||||
)
|
||||
|
||||
url = fields.URL(
|
||||
required=True,
|
||||
metadata=dict(
|
||||
description='URL of the feed entry',
|
||||
example='https://some-website/articles/1234',
|
||||
)
|
||||
metadata={
|
||||
'description': 'URL of the feed entry',
|
||||
'example': 'https://some-website/articles/1234',
|
||||
},
|
||||
)
|
||||
|
||||
published = DateTime(
|
||||
required=True,
|
||||
metadata=dict(description='Entry published time')
|
||||
required=True, metadata={'description': 'Entry published time'}
|
||||
)
|
||||
|
||||
title = fields.String(metadata=dict(description='Feed entry title'))
|
||||
summary = fields.String(metadata=dict(description='Feed entry summary'))
|
||||
content = fields.String(metadata=dict(description='Feed entry content'))
|
||||
title = fields.String(metadata={'description': 'Feed entry title'})
|
||||
summary = fields.String(metadata={'description': 'Feed entry summary'})
|
||||
content = fields.String(metadata={'description': 'Feed entry content'})
|
||||
author = fields.String(metadata={'description': 'Feed entry author'})
|
||||
tags = fields.List(
|
||||
fields.String(),
|
||||
metadata={'description': 'Feed entry tags'},
|
||||
)
|
||||
|
|
|
@ -4,7 +4,7 @@ commit = True
|
|||
tag = True
|
||||
|
||||
[metadata]
|
||||
description-file = README.md
|
||||
description_file = README.md
|
||||
|
||||
[flake8]
|
||||
max-line-length = 120
|
||||
|
|
Loading…
Reference in a new issue