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

Add The Globe and Mail #587

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions docs/supported_publishers.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@
<td>&#160;</td>
<td>&#160;</td>
</tr>
<tr>
<td>
<code>TheGlobeAndMail</code>
</td>
<td>
<div>The Globe and Mail</div>
</td>
<td>
<a href="https://www.theglobeandmail.com">
<span>www.theglobeandmail.com</span>
</a>
</td>
<td>&#160;</td>
<td>&#160;</td>
</tr>
</tbody>
</table>

Expand Down
10 changes: 10 additions & 0 deletions src/fundus/publishers/ca/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from fundus.publishers.base_objects import Publisher, PublisherGroup
from fundus.publishers.ca.cbc_news import CBCNewsParser
from fundus.publishers.ca.globe_and_mail import TheGlobeAndMailParser
from fundus.scraping.url import NewsMap, RSSFeed, Sitemap

# noinspection PyPep8Naming
Expand All @@ -16,3 +17,12 @@ class CA(metaclass=PublisherGroup):
RSSFeed("https://www.cbc.ca/webfeed/rss/rss-canada"),
],
)
TheGlobeAndMail = Publisher(
name="The Globe and Mail",
domain="https://www.theglobeandmail.com",
parser=TheGlobeAndMailParser,
sources=[
NewsMap("https://www.theglobeandmail.com/arc/outboundfeeds/news-sitemap-index/?outputType=xml"),
Sitemap("https://www.theglobeandmail.com/arc/outboundfeeds/sitemap-index/?outputType=xml"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this doesn't seem to be a propper Sitemap but just another NewsMap since it only dates back one week.

],
)
49 changes: 49 additions & 0 deletions src/fundus/publishers/ca/globe_and_mail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import datetime
from typing import List, Optional

from lxml.cssselect import CSSSelector

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 TheGlobeAndMailParser(ParserProxy):
class V1(BaseParser):
_subheadline_selector = CSSSelector("article > h4")
_paragraph_selector = CSSSelector("article > p")

@attribute
def body(self) -> ArticleBody:
return extract_article_body_with_selector(
self.precomputed.doc,
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 topics(self) -> List[str]:
topic_list = [topic.lower() for topic in generic_topic_parsing(self.precomputed.meta.get("keywords"))]
topic_set = set(topic_list)
topic_duplicates = list(topic_list)
for element in topic_set:
topic_duplicates.remove(element)
for duplicate in topic_duplicates:
topic_list.remove(duplicate)
return [topic.title() for topic in topic_list if "news" not in topic]
37 changes: 37 additions & 0 deletions tests/resources/parser/test_data/ca/TheGlobeAndMail.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"V1": {
"authors": [
"Reuters"
],
"body": {
"summary": [],
"sections": [
{
"headline": [],
"paragraphs": [
"Cannabis firm Canopy Growth WEED-T said on Friday its CEO, David Klein, will retire at the end of the company’s current fiscal year on March 31.",
"Klein was appointed as Canopy Growth’s chairman when the then co-CEO and founder Bruce Linton was fired in 2019.",
"The announcement comes just days after the company reported a smaller-than-expected core loss and pointed to easing doubts around its ability to continue as a going concern.",
"The company had raised doubts about its ability to continue as a going concern last year as it struggled to turn profitable. It later sold its sports nutrition products unit, Biosteel, after seeking bankruptcy protection for it.",
"Canopy Growth said it is in the process of securing a search firm to initiate a comprehensive CEO selection process."
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to use an article including all selectable content (subheadline, paragraphs) as test case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll keep that in mind for future publishers as well :)

}
]
},
"publishing_date": "2024-08-16 12:27:08.062000+00:00",
"title": "Canopy Growth CEO David Klein to retire at end of March",
"topics": [
"Company",
"Process",
"Ability",
"Concern",
"Ceo",
"Klein",
"End",
"Co-Ceo",
"David Klein",
"Canopy Growth Weed-T",
"Bruce Linton"
]
}
}
Binary file not shown.
4 changes: 4 additions & 0 deletions tests/resources/parser/test_data/ca/meta.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"CBCNews_2024_08_08.html.gz": {
"url": "https://www.cbc.ca/news/world/gaza-israel-ceasefire-negotiations-sinwar-1.7287711?cmp=rss",
"crawl_date": "2024-08-08 23:53:17.604667"
},
"TheGlobeAndMail_2024_08_16.html.gz": {
"url": "https://www.theglobeandmail.com/business/article-canopy-growth-ceo-david-klein-to-retire-at-end-of-march/",
"crawl_date": "2024-08-16 14:45:35.165117"
}
}