587c5510132d4e02c3667cebb06acbf50ae55a8b
[kiosk.git] / wsj_rss_renderer.py
1 #!/usr/bin/env python3
2
3 import xml
4 from typing import Dict, List
5
6 import generic_news_rss_renderer as gnrssr
7
8
9 class wsj_rss_renderer(gnrssr.generic_news_rss_renderer):
10     def __init__(
11         self,
12         name_to_timeout_dict: Dict[str, int],
13         feed_site: str,
14         feed_uris: List[str],
15         page_title: str,
16     ):
17         super(wsj_rss_renderer, self).__init__(
18             name_to_timeout_dict, feed_site, feed_uris, page_title
19         )
20         self.debug = True
21
22     def debug_prefix(self) -> str:
23         return f"wsj({self.page_title})"
24
25     def get_headlines_page_prefix(self) -> str:
26         return f"wsj-{self.page_title}"
27
28     def get_details_page_prefix(self) -> str:
29         return f"wsj-details-{self.page_title}"
30
31     def find_image(self, item: xml.etree.ElementTree.Element) -> str:
32         image = item.findtext("image")
33         if image is not None:
34             url = image.get("url")
35             return url
36         return None
37
38     def should_use_https(self) -> bool:
39         return True
40
41     def item_is_interesting_for_headlines(
42         self, title: str, description: str, item: xml.etree.ElementTree.Element
43     ) -> bool:
44         if self.is_item_older_than_n_days(item, 7):
45             return False
46         return "WSJ.com" not in title and "WSJ.com" not in description
47
48     def item_is_interesting_for_article(
49         self, title: str, description: str, item: xml.etree.ElementTree.Element
50     ) -> bool:
51         if self.is_item_older_than_n_days(item, 7):
52             return False
53         return "WSJ.com" not in title and "WSJ.com" not in description
54
55
56 # Test
57 # x = wsj_rss_renderer(
58 #    {"Fetch News" : 1,
59 #     "Shuffle News" : 1},
60 #    "feeds.a.dj.com",
61 #    [ "/rss/RSSWorldNews.xml" ],
62 #    "Test" )
63 # if x.fetch_news() == 0:
64 #    print "Error fetching news, no items fetched."
65 # x.shuffle_news()