36ef68b5e8b761d106a01d61bef991cb5d54e38c
[kiosk.git] / urbanist_renderer.py
1 #!/usr/bin/env python3
2
3 import datetime
4 import re
5 from typing import Dict, List, Optional
6 import xml
7
8 from dateutil.parser import parse
9
10 import generic_news_rss_renderer as gnrss
11
12
13 # https://www.theurbanist.org/feed/
14 class urbanist_renderer(gnrss.generic_news_rss_renderer):
15     """Read the TheUrbanist feed."""
16
17     def __init__(
18         self,
19         name_to_timeout_dict: Dict[str, int],
20         feed_site: str,
21         feed_uris: List[str],
22         page_title: str,
23     ):
24         super(urbanist_renderer, self).__init__(
25             name_to_timeout_dict, feed_site, feed_uris, page_title
26         )
27         self.debug = True
28
29     def debug_prefix(self) -> str:
30         return f"urbanist({self.page_title})"
31
32     def get_headlines_page_prefix(self) -> str:
33         return "urbanist"
34
35     def get_details_page_prefix(self) -> str:
36         return "urbanist-details"
37
38     def should_use_https(self) -> bool:
39         return True
40
41     def get_event_time(self, item: xml.etree.ElementTree.Element) -> Optional[datetime.datetime]:
42         return parse(self.find_pubdate(item))
43
44     def item_is_interesting_for_headlines(
45         self, title: str, description: str, item: xml.etree.ElementTree.Element
46     ) -> bool:
47         return description.lower() != 'the urbanist'
48
49     def do_details(self) -> bool:
50         return True
51
52     def item_is_interesting_for_article(
53         self, title: str, description: str, item: xml.etree.ElementTree.Element
54     ) -> bool:
55         return len(description) > 20
56
57
58 # Test
59 #x = urbanist_renderer(
60 #   {"Fetch News" : 1,
61 #    "Shuffle News" : 1},
62 #    "www.theurbanist.org",
63 #   [ "/feed/" ],
64 #   "Test" )
65 #if x.fetch_news() == 0:
66 #    print("Error fetching news, no items fetched.")
67 #else:
68 #    x.shuffle_news()