|
| 1 | +from datetime import date, datetime |
| 2 | +from typing import List, Optional |
| 3 | + |
| 4 | +from lxml.cssselect import CSSSelector |
| 5 | +from lxml.etree import XPath |
| 6 | + |
| 7 | +from fundus.parser import ParserProxy, BaseParser, attribute |
| 8 | +#from fundus.parser import ArticleBody, BaseParser, Image, ParserProxy, attribute |
| 9 | +from fundus.parser.utility import ( |
| 10 | + extract_article_body_with_selector, |
| 11 | + generic_author_parsing, |
| 12 | + generic_date_parsing, |
| 13 | + image_extraction, |
| 14 | +) |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +class PravdaParser(ParserProxy): |
| 19 | + class V1(BaseParser): |
| 20 | + #_summary_selector = XPath( |
| 21 | + |
| 22 | + #"//p[@class='post__excerpt'] | //h2[preceding-sibling::h1[contains(@class, 'post__title')]]" |
| 23 | + #) |
| 24 | + #_paragraph_selector = CSSSelector("div.entry-content > div.entry-content__content > p, blockquote > p") |
| 25 | + #_subheadline_selector = CSSSelector("div.entry-content > div.entry-content__content > h2") |
| 26 | + |
| 27 | + #@attribute |
| 28 | + #def body(self) -> Optional[ArticleBody]: |
| 29 | + #return extract_article_body_with_selector( |
| 30 | + #self.precomputed.doc, |
| 31 | + #summary_selector=self._summary_selector, |
| 32 | + #subheadline_selector=self._subheadline_selector, |
| 33 | + #paragraph_selector=self._paragraph_selector, |
| 34 | + #) |
| 35 | + |
| 36 | + @attribute |
| 37 | + def title(self) -> Optional[str]: |
| 38 | + return self.precomputed.ld.xpath_search("NewsArticle/headline")[0] |
| 39 | + |
| 40 | + @attribute |
| 41 | + def authors(self) -> List[str]: |
| 42 | + # The first hit is the name of the news source itself |
| 43 | + print(generic_author_parsing(self.precomputed.ld.xpath_search('NewsArticle/author/name')[1:])) |
| 44 | + return generic_author_parsing(self.precomputed.ld.xpath_search('NewsArticle/author/name')[1:]) |
| 45 | + |
| 46 | + @attribute |
| 47 | + def publishing_date(self) -> Optional[datetime]: |
| 48 | + return generic_date_parsing(self.precomputed.ld.xpath_search("NewsArticle/datePublished")[1]) |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + |
0 commit comments