Defined RssPost and RssDataSourceInterface
This commit is contained in:
parent
e514fee924
commit
beeac85894
2 changed files with 37 additions and 0 deletions
28
Calendar/RssInterface.py
Normal file
28
Calendar/RssInterface.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
from DataSourceInterface import DataSourceInterface
|
||||
from datetime import datetime, timezone, timedelta
|
||||
|
||||
class RssInterface(DataSourceInterface):
|
||||
"""Interface for fetching and processing rss post information."""
|
||||
def __init__(self):
|
||||
self.loaded_posts = self.__get_posts__()
|
||||
self.__sort_posts__()
|
||||
|
||||
def __get_posts__(self):
|
||||
raise NotImplementedError("Functions needs to be implemented")
|
||||
|
||||
def get_latest_posts(self, count=10):
|
||||
return self.loaded_posts[0:count]
|
||||
|
||||
def get_today_posts(self):
|
||||
return self.get_day_posts(datetime.now())
|
||||
|
||||
def get_day_posts(self, day):
|
||||
return self.__get_posts_to_filter__(lambda x : x.datetime.strftime('%d-%m-%y') == date.strftime('%d-%m-%y'))
|
||||
|
||||
def __get_posts_to_filter__(self, post_filter):
|
||||
if self.loaded_posts is None:
|
||||
return []
|
||||
return [post for post in self.loaded_posts if post_filter(post)]
|
||||
|
||||
def __sort_posts__(self):
|
||||
self.loaded_posts.sort(key=lambda x : x.datetime)
|
9
Calendar/RssPost.py
Normal file
9
Calendar/RssPost.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
class RssPost(object):
|
||||
"""Defines a rss post, independent of any implementation"""
|
||||
def __init__ (self):
|
||||
self.title = None
|
||||
self.description = None
|
||||
self.source = None
|
||||
|
||||
self.datetime = None
|
||||
self.fetch_datetime = None
|
Loading…
Reference in a new issue