-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into add-taipei-times
# Conflicts: # src/fundus/publishers/__init__.py
- Loading branch information
Showing
23 changed files
with
499 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import datetime | ||
from typing import List, Optional | ||
|
||
from lxml.etree import XPath | ||
|
||
from fundus.parser import ArticleBody, BaseParser, Image, ParserProxy, attribute | ||
from fundus.parser.utility import ( | ||
extract_article_body_with_selector, | ||
generic_author_parsing, | ||
generic_date_parsing, | ||
image_extraction, | ||
) | ||
|
||
|
||
class ZwanzigMinutenParser(ParserProxy): | ||
class V1(BaseParser): | ||
_summary_selector = XPath( | ||
"//div[@class='Article_elementLead__N3pGr']/p | (//div[@type='typeInfoboxSummary'])[1]//li" | ||
) | ||
_subheadline_selector = XPath("//section[@class='Article_body__60Liu']//h2[contains(@class, 'crosshead')]") | ||
_paragraph_selector = XPath("//div[@class='Article_elementTextblockarray__WNyan']/p") | ||
|
||
@attribute | ||
def body(self) -> Optional[ArticleBody]: | ||
return extract_article_body_with_selector( | ||
self.precomputed.doc, | ||
summary_selector=self._summary_selector, | ||
subheadline_selector=self._subheadline_selector, | ||
paragraph_selector=self._paragraph_selector, | ||
) | ||
|
||
@attribute | ||
def authors(self) -> List[str]: | ||
return generic_author_parsing(self.precomputed.ld.bf_search("author")) | ||
|
||
@attribute | ||
def publishing_date(self) -> Optional[datetime.datetime]: | ||
return generic_date_parsing(self.precomputed.ld.bf_search("datePublished")) | ||
|
||
@attribute | ||
def title(self) -> Optional[str]: | ||
return self.precomputed.meta.get("og:title") | ||
|
||
@attribute | ||
def images(self) -> List[Image]: | ||
return image_extraction( | ||
doc=self.precomputed.doc, | ||
paragraph_selector=self._paragraph_selector, | ||
upper_boundary_selector=XPath("//article"), | ||
caption_selector=XPath("./ancestor::figure//figcaption/span[@class='sc-d47814d6-2 bDLFoO']/p"), | ||
author_selector=XPath("./ancestor::figure//figcaption/span[@class='sc-d47814d6-3 bmEwwn']"), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from datetime import datetime, timedelta | ||
|
||
from dateutil.rrule import MONTHLY, rrule | ||
|
||
from fundus.publishers.base_objects import Publisher, PublisherGroup | ||
from fundus.publishers.it.la_repubblica import LaRepubblicaParser | ||
from fundus.scraping.url import RSSFeed, Sitemap | ||
|
||
|
||
class IT(metaclass=PublisherGroup): | ||
LaRepubblica = Publisher( | ||
name="La Repubblica", | ||
domain="https://www.repubblica.it", | ||
parser=LaRepubblicaParser, | ||
sources=[ | ||
RSSFeed("https://www.repubblica.it/rss/homepage/rss2.0.xml"), | ||
] | ||
+ [ | ||
Sitemap(f"https://www.repubblica.it/sitemap-{date.strftime('%Y-%m')}.xml") | ||
for date in reversed( | ||
list(rrule(MONTHLY, dtstart=datetime(2020, 1, 1), until=datetime.now() + timedelta(days=30))) | ||
) | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from datetime import datetime | ||
from typing import List, Optional | ||
|
||
from lxml.cssselect import CSSSelector | ||
from lxml.etree import XPath | ||
|
||
from fundus.parser import ArticleBody, BaseParser, ParserProxy, attribute | ||
from fundus.parser.utility import ( | ||
extract_article_body_with_selector, | ||
generic_author_parsing, | ||
generic_date_parsing, | ||
generic_topic_parsing, | ||
) | ||
|
||
|
||
class LaRepubblicaParser(ParserProxy): | ||
class V1(BaseParser): | ||
# Selectors for article body parts | ||
_summary_selector = CSSSelector("div.story__summary p") | ||
_paragraph_selector = CSSSelector("div.story__text p") | ||
_subheadline_selector = CSSSelector("div.story__text h2") | ||
|
||
@attribute | ||
def title(self) -> Optional[str]: | ||
# Get the headline from og:title meta tag | ||
return self.precomputed.meta.get("og:title") | ||
|
||
@attribute | ||
def body(self) -> Optional[ArticleBody]: | ||
# Extract article body using utility function | ||
return extract_article_body_with_selector( | ||
self.precomputed.doc, | ||
paragraph_selector=self._paragraph_selector, | ||
subheadline_selector=self._subheadline_selector, | ||
) | ||
|
||
@attribute | ||
def authors(self) -> List[str]: | ||
# Extract authors from schema.org NewsArticle data | ||
authors = self.precomputed.ld.xpath_search("//NewsArticle/author") | ||
if authors: | ||
return generic_author_parsing(authors) | ||
return [] | ||
|
||
@attribute | ||
def publishing_date(self) -> Optional[datetime]: | ||
# Use scalar parameter for direct value | ||
date_str = self.precomputed.ld.xpath_search("//NewsArticle/datePublished", scalar=True) | ||
return generic_date_parsing(date_str) | ||
|
||
@attribute | ||
def topics(self) -> List[str]: | ||
# Simplified topic extraction using name in xpath | ||
topics = self.precomputed.ld.xpath_search("//NewsArticle/about/name") | ||
return generic_topic_parsing(topics) if topics else [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.