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 Taipei Times #639

Closed
wants to merge 7 commits into from
Closed
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
Prev Previous commit
add images to TaipeiTimes
addie9800 committed Dec 17, 2024
commit a378007389775236a7fe55e8270ca6e5e8ca6538
14 changes: 13 additions & 1 deletion src/fundus/publishers/tw/TaipeiTimes.py
Original file line number Diff line number Diff line change
@@ -4,11 +4,12 @@

from lxml.etree import XPath

from fundus.parser import ArticleBody, BaseParser, ParserProxy, attribute
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,
)


@@ -47,3 +48,14 @@ def publishing_date(self) -> Optional[datetime.datetime]:
@attribute
def title(self) -> Optional[str]:
return self.precomputed.ld.bf_search("headline")

@attribute
def images(self) -> List[Image]:
return image_extraction(
doc=self.precomputed.doc,
paragraph_selector=self._paragraph_selector,
upper_boundary_selector=XPath("//div[@class='archives']"),
image_selector=XPath("//div[@class='imgboxa']//img"),
caption_selector=XPath("./ancestor::div[@class='imgboxa']//h1"),
author_selector=XPath("./ancestor::div[@class='imgboxa']//p"),
)
19 changes: 19 additions & 0 deletions tests/resources/parser/test_data/tw/TaipeiTimes.json
Original file line number Diff line number Diff line change
@@ -33,6 +33,25 @@
}
]
},
"images": [
{
"versions": [
{
"url": "https://www.taipeitimes.com/images/2024/10/16/P01-241016-317.jpg",
"query_width": null,
"size": null,
"type": "image/jpeg"
}
],
"is_cover": false,
"description": null,
"caption": "Philippine Marine Corps Commandant Major-General Arturo Roja, second left, US Marines exercise representative Colonel Stuart Glenn, left, and Philippine Marine Corps and exercise director Brigadier General Vicente Blanco, second right, take part in the opening ceremony of the annual Kamandag joint military exercises at the Philippine Marines officers’ club at Fort Bonifacio, Metro Manila, yesterday.",
"authors": [
"AFP"
],
"position": 170
}
],
"publishing_date": "2024-10-16 00:00:00+08:00",
"title": "US, Manila launch war games after PRC’s Taiwan drills"
}