18ed2fc3b97e9de3c64e32538a7349d160be6bf1
[kiosk.git] / seattletimes_rss_renderer.py
1 import datetime
2 import generic_news_rss_renderer as gnrss
3
4
5 class seattletimes_rss_renderer(gnrss.generic_news_rss_renderer):
6     interesting_categories = frozenset(
7         [
8             "Nation",
9             "World",
10             "Life",
11             "Technology" "Local News",
12             "Food",
13             "Drink",
14             "Today File",
15             "Seahawks",
16             "Oddities",
17             "Packfic NW",
18             "Home",
19             "Garden",
20             "Travel",
21             "Outdoors",
22         ]
23     )
24
25     def __init__(self, name_to_timeout_dict, feed_site, feed_uris, page_title):
26         super(seattletimes_rss_renderer, self).__init__(
27             name_to_timeout_dict, feed_site, feed_uris, page_title
28         )
29
30     def debug_prefix(self):
31         return "seattletimes"
32
33     def get_headlines_page_prefix(self):
34         return "seattletimes-nonnews"
35
36     def get_details_page_prefix(self):
37         return "seattletimes-details-nonnews"
38
39     def should_use_https(self):
40         return True
41
42     def item_is_interesting_for_headlines(self, title, description, item):
43         if item.tag != "item":
44             self.debug_print("Item.tag isn't item?!")
45             return False
46         if self.is_item_older_than_n_days(item, 14):
47             self.debug_print("%s: is too old!" % title)
48             return False
49
50         details = {}
51         for detail in item.getchildren():
52             self.debug_print(
53                 "detail %s => %s (%s)" % (detail.tag, detail.attrib, detail.text)
54             )
55             if detail.text != None:
56                 details[detail.tag] = detail.text
57         if "category" not in details:
58             self.debug_print("No category in details?!")
59             self.debug_print(details)
60             return False
61
62         interesting = False
63         for x in seattletimes_rss_renderer.interesting_categories:
64             if x in details["category"]:
65                 self.debug_print("%s looks like a good category." % x)
66                 interesting = True
67         if not interesting:
68             return False
69         return True
70
71     def item_is_interesting_for_article(self, title, description, item):
72         if self.is_item_older_than_n_days(item, 14):
73             self.debug_print("%s: is too old!" % title)
74             return False
75         return len(description) >= 65
76
77
78 # Test
79 # x = seattletimes_rss_renderer({"Test", 123},
80 #                              "www.seattletimes.com",
81 #                              [ "/life/feed/" ],
82 #                              "nonnews")
83 # x.periodic_render("Fetch News")
84 # x.periodic_render("Shuffle News")