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