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 indian publisher Bhaskar #605

Merged
merged 3 commits into from
Sep 10, 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
15 changes: 15 additions & 0 deletions docs/supported_publishers.md
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,21 @@
</tr>
</thead>
<tbody>
<tr>
<td>
<code>Bhaskar</code>
</td>
<td>
<div>Dainik Bhaskar</div>
</td>
<td>
<a href="https://www.bhaskar.com/">
<span>www.bhaskar.com</span>
</a>
</td>
<td>&#160;</td>
<td>&#160;</td>
</tr>
<tr>
<td>
<code>TimesOfIndia</code>
Expand Down
10 changes: 9 additions & 1 deletion src/fundus/publishers/ind/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from fundus.publishers.base_objects import Publisher, PublisherGroup
from fundus.publishers.ind.bhaskar import BhaskarParser
from fundus.publishers.ind.times_of_india import TimesOfIndiaParser
from fundus.scraping.url import NewsMap, RSSFeed
from fundus.scraping.url import NewsMap, RSSFeed, Sitemap


class IND(metaclass=PublisherGroup):
Expand All @@ -15,3 +16,10 @@ class IND(metaclass=PublisherGroup):
RSSFeed("https://timesofindia.indiatimes.com/rssfeedmostrecent.cms"),
],
)

Bhaskar = Publisher(
name="Dainik Bhaskar",
domain="https://www.bhaskar.com/",
parser=BhaskarParser,
sources=[NewsMap("https://www.bhaskar.com/sitemaps-v1--sitemap-google-news-index.xml")],
)
47 changes: 47 additions & 0 deletions src/fundus/publishers/ind/bhaskar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import datetime
import re
from typing import List, Optional, Pattern

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 BhaskarParser(ParserProxy):
class V1(BaseParser):
_paragraph_selector = XPath("//article //p | //article //*[@style='border-bottom:none'] //li")

_topic_bloat_pattern: Pattern[str] = re.compile(r"news", flags=re.IGNORECASE)

@attribute
def body(self) -> ArticleBody:
return extract_article_body_with_selector(
doc=self.precomputed.doc,
paragraph_selector=self._paragraph_selector,
)

@attribute
def publishing_date(self) -> Optional[datetime.datetime]:
return generic_date_parsing(self.precomputed.ld.bf_search("datePublished"))

@attribute
def authors(self) -> List[str]:
return generic_author_parsing(self.precomputed.ld.bf_search("author"))

@attribute
def title(self) -> Optional[str]:
return self.precomputed.ld.bf_search("headline")

@attribute
def topics(self) -> List[str]:
return [
topic
for topic in generic_topic_parsing(self.precomputed.ld.bf_search("keywords"))
if not re.search(self._topic_bloat_pattern, topic)
]
28 changes: 28 additions & 0 deletions tests/resources/parser/test_data/ind/Bhaskar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"V1": {
"authors": [
"दैनिक भास्कर"
],
"body": {
"summary": [],
"sections": [
{
"headline": [],
"paragraphs": [
"समस्तीपुर के बंगरा थाना क्षेत्र के रहीमाबाद गांव में 2 दिन पहले हुए मोहम्मद तबरेज के घर चोरी मामले का पुलिस ने बुधवार को खुलासा कर लिया है। पुलिस ने इस मामले में ताजपुर भेरोखड़ा गांव में छापेमारी कर चोरी का गहना आदि के साथ 2 बदमाशों को गिरफ्तार किया",
"गिरफ्तार बदमाश की पहचान ताजपुर थाना क्षेत्र के भेरोखड़ा गांव निवासी विद्यानंद तिवारी का बेटा संजीत कुमार और मोहम्मद इजराइल का बेटा मोहम्मद मुराद के रूप में की गई है। दोनों बदमाशों के पास से चोरी के जेवरात बरामद किए गए हैं।",
"ASP संजय पांडे ने संवाददाता सम्मेलन के दौरान जानकारी देते हुए बताया कि चोरी की घटना के बाद बंगरा थाना अध्यक्ष मनीषा कुमारी के नेतृत्व में SIT का गठन किया गया था। पुलिस ने तकनीकी और मानवीय सूचना के आधार पर भेरोखड़ा गांव में छापेमारी कर उक्त दोनों युवक को गिरफ्तार किया। उससे पूछताछ शुरू की तो इस चोरी कांड का खुलासा हो गया। पुलिस ने उसके घर से चोरी में गायब हुआ गहना और कुछ नगद राशि भी बरामद की। एसपी ने बताया कि दोनों बदमाश चोरी का गहना बेचने के फिराक में था। इसी दौरान पुलिस को भनक लग गई।",
"1 सितंबर की रात हुई थी चोरी",
"बता दें कि रहीमाबाद गांव निवासी मोहम्मद तबरेज 1 सितंबर को घर पर नहीं थे। इसी दौरान उनके घर में घुसकर बदमाशों ने गोदरेज का ताला काट कर एक लाख रुपए नगद के अलावा 10 लाख रुपए मूल्य से अधिक का गहना चोरी कर लिया था। चोरी की घटना के बाद पीड़ित परिवार द्वारा प्राथमिकी दर्ज कराई गई थी। प्राथमिकी दर्ज होने के बाद पुलिस ने इस मामले में अनुसंधान शुरू किया था।",
"ASP ने बताया कि अब गिरफ्तार दोनों बदमाश को जेल भेजा जा रहा है। छापेमारी टीम में थाना अध्यक्ष मनीषा कुमारी के अलावा अपर थाना अध्यक्ष प्रीति कुमारी, दरोगा राम अवधेश सिंह आदि पुलिस पदाधिकारी साथ में थे।"
]
}
]
},
"publishing_date": "2024-09-04 16:20:35+05:30",
"title": "समस्तीपुर पुलिस ने 2 बदमाशों को पकड़ा: दो दिनों के अंदर चोरी कांड का किया खुलासा, गहना भी बरामद",
"topics": [
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would also consider filtering topics containting news

"Samastipur police caught 2 miscreants"
]
}
}
Binary file not shown.
4 changes: 4 additions & 0 deletions tests/resources/parser/test_data/ind/meta.info
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"Bhaskar_2024_09_04.html.gz": {
"url": "https://www.bhaskar.com/local/bihar/samastipur/news/samastipur-police-caught-2-miscreants-133589711.html",
"crawl_date": "2024-09-04 12:50:44.805947"
},
"TimesOfIndia_2024_09_02.html.gz": {
"url": "https://timesofindia.indiatimes.com/world/pakistan/anti-terror-op-turns-sinister-pakistani-netizens-being-walled-off-as-army-raises-spectre-of-digital-terrorism/articleshow/112898501.cms",
"crawl_date": "2024-09-02 23:12:24.525515"
Expand Down