3 from bs4 import BeautifulSoup # type: ignore
5 from typing import Dict, List, Optional
7 import xml.etree.ElementTree as ET
9 import generic_news_rss_renderer
12 class google_news_rss_renderer(generic_news_rss_renderer.generic_news_rss_renderer):
15 name_to_timeout_dict: Dict[str, int],
20 super(google_news_rss_renderer, self).__init__(
21 name_to_timeout_dict, feed_site, feed_uris, page_title
25 def debug_prefix(self) -> str:
28 def get_headlines_page_prefix(self) -> str:
31 def get_details_page_prefix(self) -> str:
32 return "google-news-details"
34 def find_description(self, item: xml.etree.ElementTree.Element) -> str:
35 descr = item.findtext("description")
36 source = item.findtext("source")
38 if source is not None:
39 descr = descr + f" (source)"
44 def munge_description_internal(self, descr: str, item: ET.Element) -> str:
47 descr = re.sub(r"\<[^\>]*$", "", descr)
48 descr = descr + " [...]"
49 descr += "</A></LI></UL></OL></P>"
52 def munge_description(self, description: str, item: ET.Element) -> str:
53 soup = BeautifulSoup(description, features="lxml")
54 for a in soup.findAll("a"):
57 return self.munge_description_internal(descr, item)
59 def find_image(self, item: xml.etree.ElementTree.Element) -> Optional[str]:
62 def should_use_https(self) -> bool:
65 def item_is_interesting_for_headlines(
66 self, title: str, description: str, item: xml.etree.ElementTree.Element
68 return not self.is_item_older_than_n_days(item, 2)
70 def item_is_interesting_for_article(
71 self, title: str, description: str, item: xml.etree.ElementTree.Element
73 return not self.is_item_older_than_n_days(item, 2)
77 # x = google_news_rss_renderer(
79 # "Shuffle News" : 1},
81 # [ "/rss?hl=en-US&gl=US&ceid=US:en" ],
83 # if x.fetch_news() == 0:
84 # print("Error fetching news, no items fetched.")
87 # 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!"
88 # d = x.munge_description_internal(descr)