Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Funke topics #555

Merged
merged 4 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/fundus/publishers/de/braunschweiger_zeitung.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class V1(BaseParser):
" or contains(text(), 'Auch interessant')"
" or contains(text(), 'Weitere News'))]"
)
_topics_selector = XPath("//div[@class='not-prose mb-4 mx-5 font-sans']/ul/li")

@attribute
def body(self) -> ArticleBody:
Expand All @@ -44,7 +45,14 @@ def title(self) -> Optional[str]:

@attribute
def topics(self) -> List[str]:
return generic_topic_parsing(self.precomputed.meta.get("news_keywords"))
if topics := generic_topic_parsing(self.precomputed.meta.get("news_keywords")):
return topics
else:
pass
return [
re.sub(r"\s*–.+", "", node.text_content()).strip()
for node in self._topics_selector(self.precomputed.doc)
]

@attribute
def authors(self) -> List[str]:
Expand Down
11 changes: 10 additions & 1 deletion src/fundus/publishers/de/hamburger_abendblatt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import datetime
import re
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 (
Expand All @@ -17,6 +19,7 @@ class V1(BaseParser):
_summary_selector = CSSSelector("div.article-body > p.font-sans")
_paragraph_selector = CSSSelector("div.article-body > p:not(.font-sans)")
_subheadline_selector = CSSSelector("div.article-body > h3")
_topics_selector = XPath("//div[@class='not-prose mb-4 mx-5 font-sans']/ul/li")

@attribute
def body(self) -> ArticleBody:
Expand All @@ -41,4 +44,10 @@ def title(self) -> Optional[str]:

@attribute
def topics(self) -> List[str]:
return generic_topic_parsing(self.precomputed.meta.get("keywords"))
if topics := generic_topic_parsing(self.precomputed.meta.get("keywords")):
return topics
else:
return [
re.sub(r"\s*–.+", "", node.text_content()).strip()
for node in self._topics_selector(self.precomputed.doc)
]
11 changes: 10 additions & 1 deletion src/fundus/publishers/de/morgenpost_berlin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import datetime
import re
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 (
Expand All @@ -17,6 +19,7 @@ class V1(BaseParser):
_summary_selector = CSSSelector("div.article-body > p.font-sans.font-medium")
_paragraph_selector = CSSSelector("div.article-body > p:not([class])")
_subheadline_selector = CSSSelector("div.article-body > h3")
_topics_selector = XPath("//div[@class='not-prose mb-4 mx-5 font-sans']/ul/li")

@attribute
def body(self) -> ArticleBody:
Expand All @@ -41,4 +44,10 @@ def title(self) -> Optional[str]:

@attribute
def topics(self) -> List[str]:
return generic_topic_parsing(self.precomputed.meta.get("keywords"))
if topics := generic_topic_parsing(self.precomputed.meta.get("keywords")):
return topics
else:
return [
re.sub(r"\s*–.+", "", node.text_content()).strip()
for node in self._topics_selector(self.precomputed.doc)
]
12 changes: 10 additions & 2 deletions src/fundus/publishers/de/waz.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import re
from typing import List, Optional

from lxml.cssselect import CSSSelector
Expand All @@ -19,6 +20,7 @@ class V1(BaseParser):
_paragraph_selector: XPath = CSSSelector(".article__body > p")
_summary_selector: XPath = CSSSelector(".article__header__intro__text")
_subheadline_selector: XPath = CSSSelector(".article__body > h3")
_topics_selector = XPath("//div[@class='not-prose mb-4 mx-5 font-sans']/ul/li")

@attribute
def body(self) -> ArticleBody:
Expand All @@ -44,8 +46,14 @@ def publishing_date(self) -> Optional[datetime.datetime]:
@attribute
def topics(self) -> List[str]:
authors = generic_author_parsing(self.precomputed.meta.get("author"))
topics = generic_topic_parsing(self.precomputed.meta.get("keywords"))
return [topic for topic in topics if topic not in authors]
if topics := generic_topic_parsing(self.precomputed.meta.get("keywords")):
return [topic for topic in topics if topic not in authors]
else:
pass
return [
re.sub(r"\s*:.+", "", node.text_content()).strip()
for node in self._topics_selector(self.precomputed.doc)
]

class V1_1(V1):
VALID_UNTIL = datetime.date.today()
Expand Down