334f10d96345fd63165d9d8bf1a4a39809bdc5ba
[kiosk.git] / google_news_rss_renderer.py
1 from bs4 import BeautifulSoup
2 import generic_news_rss_renderer
3 import re
4
5 class google_news_rss_renderer(generic_news_rss_renderer.generic_news_rss_renderer):
6     def __init__(self, name_to_timeout_dict, feed_site, feed_uris, page_title):
7         super(google_news_rss_renderer, self).__init__(
8             name_to_timeout_dict,
9             feed_site,
10             feed_uris,
11             page_title)
12         self.debug = 1
13
14     def debug_prefix(self):
15         return "google-news"
16
17     def get_headlines_page_prefix(self):
18         return "google-news"
19
20     def get_details_page_prefix(self):
21         return "google-news-details"
22
23     def find_description(self, item):
24         descr = item.findtext('description')
25         source = item.findtext('source')
26         if source is not None:
27             descr = descr + " (%s)" % source
28         return descr
29
30     def munge_description(self, description):
31         soup = BeautifulSoup(description)
32         for a in soup.findAll('a'):
33             del a['href']
34         return str(soup)
35
36     def find_image(self, item):
37         return None
38
39     def should_use_https(self):
40         return True
41
42     def item_is_interesting_for_headlines(self, title, description, item):
43         return not self.is_item_older_than_n_days(item, 2)
44
45     def item_is_interesting_for_article(self, title, description, item):
46         return not self.is_item_older_than_n_days(item, 2)
47
48 # Test
49 #x = google_news_rss_renderer(
50 #    {"Fetch News" : 1,
51 #     "Shuffle News" : 1},
52 #    "news.google.com",
53 #    [ "/rss?hl=en-US&gl=US&ceid=US:en" ],
54 #    "Test" )
55 #if x.fetch_news() == 0:
56 #    print("Error fetching news, no items fetched.")
57 #x.shuffle_news()