2019-03-04 20:09:23 +01:00
|
|
|
from DesignEntity import DesignEntity
|
2019-05-01 07:17:40 +02:00
|
|
|
from TableDesign import TableDesign
|
2019-03-24 21:27:32 +01:00
|
|
|
from Assets import defaultfontsize
|
2019-03-04 20:09:23 +01:00
|
|
|
|
|
|
|
class RssPostListDesign (DesignEntity):
|
2019-05-01 07:17:40 +02:00
|
|
|
"""Creates a TableDesign filled with rss post
|
2019-03-04 20:09:23 +01:00
|
|
|
date and title"""
|
2019-03-24 21:27:32 +01:00
|
|
|
def __init__ (self, size, rssfeed, text_size = defaultfontsize):
|
2019-03-04 20:09:23 +01:00
|
|
|
super(RssPostListDesign, self).__init__(size)
|
|
|
|
self.rssfeed = rssfeed
|
|
|
|
self.__post_matrix__ = []
|
|
|
|
self.text_size = text_size
|
|
|
|
|
|
|
|
def __finish_image__ (self):
|
|
|
|
self.__fill_post_matrix__()
|
|
|
|
|
2019-05-06 11:05:10 +02:00
|
|
|
table_design = TableDesign(self.size, line_spacing=5, col_spacing=3, matrix=self.__post_matrix__, fontsize = self.text_size, mask=False, truncate_cols=False, wrap=True)
|
2019-03-04 20:09:23 +01:00
|
|
|
self.draw_design(table_design)
|
|
|
|
|
|
|
|
def __get_formatted_post__ (self, post):
|
|
|
|
date = post.datetime.strftime('%d %b')
|
|
|
|
date = self.__remove_leading_zero__(date)
|
2019-04-07 11:47:47 +02:00
|
|
|
return [ '', '•', post.title ]
|
2019-03-04 20:09:23 +01:00
|
|
|
|
|
|
|
def __remove_leading_zero__(self, text):
|
|
|
|
while text[0] is '0':
|
|
|
|
text = text[1:]
|
|
|
|
return text
|
|
|
|
|
|
|
|
def __fill_post_matrix__ (self):
|
|
|
|
for post in self.rssfeed.get_latest_posts():
|
|
|
|
row = self.__get_formatted_post__(post)
|
|
|
|
self.__post_matrix__.append(row)
|