Skip to content

Commit b8ec85d

Browse files
authored
Merge pull request #736 from flairNLP/add-iceland
Add `ISL`
2 parents 443fa83 + 446a48c commit b8ec85d

8 files changed

Lines changed: 285 additions & 1 deletion

File tree

docs/supported_publishers.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,44 @@
15491549
</table>
15501550

15511551

1552+
## ISL-Publishers
1553+
1554+
<table class="publishers isl">
1555+
<thead>
1556+
<tr>
1557+
<th>Class&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</th>
1558+
<th>Name&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</th>
1559+
<th>URL&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</th>
1560+
<th>Languages</th>
1561+
<th>Missing&#160;Attributes</th>
1562+
<th>Additional&#160;Attributes&#160;&#160;&#160;&#160;</th>
1563+
</tr>
1564+
</thead>
1565+
<tbody>
1566+
<tr>
1567+
<td>
1568+
<code>Morgunbladid</code>
1569+
</td>
1570+
<td>
1571+
<div>Morgunbladid</div>
1572+
</td>
1573+
<td>
1574+
<a href="https://www.mbl.is/">
1575+
<span>www.mbl.is</span>
1576+
</a>
1577+
</td>
1578+
<td>
1579+
<code>is</code>
1580+
</td>
1581+
<td>
1582+
<code>topics</code>
1583+
</td>
1584+
<td>&#160;</td>
1585+
</tr>
1586+
</tbody>
1587+
</table>
1588+
1589+
15521590
## IT-Publishers
15531591

15541592
<table class="publishers it">

src/fundus/parser/utility.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,12 @@ def get_versions_from_node(
642642

643643
def parse_versions(img_node: lxml.html.HtmlElement, size_pattern: Optional[Pattern[str]] = None) -> List[ImageVersion]:
644644
# parse img
645-
if (default_width := img_node.get("width")) and (default_height := img_node.get("height")):
645+
if (
646+
(default_width := img_node.get("width"))
647+
and not default_width == "auto"
648+
and (default_height := img_node.get("height"))
649+
and not default_height == "auto"
650+
):
646651
ratio = float(default_width) / float(default_height)
647652
else:
648653
ratio = None

src/fundus/publishers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from fundus.publishers.fr import FR
1616
from fundus.publishers.gl import GL
1717
from fundus.publishers.ind import IND
18+
from fundus.publishers.isl import ISL
1819
from fundus.publishers.it import IT
1920
from fundus.publishers.jp import JP
2021
from fundus.publishers.lt import LT
@@ -68,6 +69,7 @@ class PublisherCollection(metaclass=PublisherCollectionMeta):
6869
us = US
6970
uk = UK
7071
fr = FR
72+
isl = ISL
7173
gl = GL
7274
ch = CH
7375
lt = LT
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from fundus.publishers.base_objects import Publisher, PublisherGroup
2+
from fundus.scraping.url import RSSFeed, Sitemap
3+
4+
from .morgunbladid import MorgunbladidParser
5+
6+
# noinspection PyPep8Naming
7+
8+
9+
class ISL(metaclass=PublisherGroup):
10+
default_language = "is"
11+
12+
Morgunbladid = Publisher(
13+
name="Morgunbladid",
14+
domain="https://www.mbl.is/",
15+
parser=MorgunbladidParser,
16+
sources=[
17+
Sitemap("https://www.mbl.is/mm/sitemap.xml"),
18+
RSSFeed("https://www.mbl.is/feeds/fp/"),
19+
RSSFeed("https://www.mbl.is/feeds/innlent/"),
20+
RSSFeed("https://www.mbl.is/feeds/erlent/"),
21+
RSSFeed("https://www.mbl.is/feeds/english/"),
22+
RSSFeed("https://www.mbl.is/feeds/helst/"),
23+
],
24+
)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import datetime
2+
import re
3+
from typing import List, Optional
4+
5+
from lxml.cssselect import CSSSelector
6+
from lxml.etree import XPath
7+
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+
generic_topic_parsing,
14+
image_extraction,
15+
)
16+
17+
18+
class MorgunbladidParser(ParserProxy):
19+
class V1(BaseParser):
20+
_summary_selector = XPath("//div[@class='main-layout']//div[@class='is-merking']/p")
21+
_paragraph_selector = XPath(
22+
"//div[@class='main-layout' or @data-element-type='body-facts']" "/p[not(a and not(text()))]"
23+
)
24+
_subheadline_selector = XPath("//div[@class='main-layout' or @class='et_pb_text_inner']/h3")
25+
26+
@attribute
27+
def body(self) -> Optional[ArticleBody]:
28+
return extract_article_body_with_selector(
29+
self.precomputed.doc,
30+
subheadline_selector=self._subheadline_selector,
31+
paragraph_selector=self._paragraph_selector,
32+
)
33+
34+
@attribute
35+
def authors(self) -> List[str]:
36+
return generic_author_parsing(self.precomputed.ld.bf_search("author"))
37+
38+
@attribute
39+
def publishing_date(self) -> Optional[datetime.datetime]:
40+
return generic_date_parsing(self.precomputed.ld.bf_search("datePublished"))
41+
42+
@attribute
43+
def title(self) -> Optional[str]:
44+
return self.precomputed.ld.bf_search("headline")
45+
46+
@attribute
47+
def images(self) -> List[Image]:
48+
return image_extraction(
49+
doc=self.precomputed.doc,
50+
paragraph_selector=self._paragraph_selector,
51+
image_selector=XPath("//div[@class='image']//img"),
52+
caption_selector=XPath("./ancestor::div[contains(@class, 'newsitem-image')]//span[@class='caption']"),
53+
author_selector=XPath("./ancestor::div[contains(@class, 'newsitem-image')]//span[@class='credit']"),
54+
)

0 commit comments

Comments
 (0)