Various changes
[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_internal(self, descr):
31         if len(descr) > 450:
32             descr = descr[:450]
33             descr = re.sub(r"\<[^\>]*$", "", descr)
34             descr = descr + " [...]"
35         descr += "</A></LI></UL></OL></P>"
36         return descr
37
38     def munge_description(self, description):
39         soup = BeautifulSoup(description)
40         for a in soup.findAll('a'):
41             del a['href']
42         descr = str(soup)
43         return munge_description_internal(descr)
44
45     def find_image(self, item):
46         return None
47
48     def should_use_https(self):
49         return True
50
51     def item_is_interesting_for_headlines(self, title, description, item):
52         return not self.is_item_older_than_n_days(item, 2)
53
54     def item_is_interesting_for_article(self, title, description, item):
55         return not self.is_item_older_than_n_days(item, 2)
56
57 # Test
58 #x = google_news_rss_renderer(
59 #    {"Fetch News" : 1,
60 #     "Shuffle News" : 1},
61 #    "news.google.com",
62 #    [ "/rss?hl=en-US&gl=US&ceid=US:en" ],
63 #    "Test" )
64 #if x.fetch_news() == 0:
65 #    print("Error fetching news, no items fetched.")
66 #x.shuffle_news()
67 #
68 #descr = "this is a lot of really long text about nothign in particular.  It's pretty interesting, don't you think?  I hope that the munge description method works by both truncating it and remembering to close any open <LI>items as well as making sure not to truncate in the middle of a <A HREF=\"whatever\" these are a bunch of useless arguments to the A tag that make it really long so that the truncate will happen in the middle of it.  I'm getting kind of tired of typing shit so I'm going to revert to copy pasta now.  Sorry if you were getting into this story.  The quick brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.</A></LI> Out!"
69 #d = x.munge_description_internal(descr)
70 #print(d)
71