mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update Danas
Fixes #1757439 [Updated recipe for Danas](https://bugs.launchpad.net/calibre/+bug/1757439)
This commit is contained in:
parent
2d2d66113d
commit
c172e54223
@ -8,7 +8,7 @@ danas.rs
|
||||
'''
|
||||
|
||||
from calibre.web.feeds.news import BasicNewsRecipe
|
||||
from datetime import date, timedelta
|
||||
from datetime import date
|
||||
|
||||
|
||||
class Danas(BasicNewsRecipe):
|
||||
@ -22,15 +22,14 @@ class Danas(BasicNewsRecipe):
|
||||
no_stylesheets = False
|
||||
use_embedded_content = False
|
||||
encoding = 'utf-8'
|
||||
masthead_url = 'http://www.danas.rs/images/basic/logo.png'
|
||||
masthead_url = 'https://www.danas.rs/wp-content/themes/danas/assets/public/images/danas-logo.png'
|
||||
language = 'sr'
|
||||
remove_javascript = True
|
||||
publication_type = 'newspaper'
|
||||
remove_empty_feeds = True
|
||||
auto_cleanup = True
|
||||
auto_cleanup_keep = '//h1[@class="title"] | //div[@class="subTitle"] | //div[@class="author"] | //div[@class="published"]'
|
||||
auto_cleanup_keep = '//div[@class="post-intro-above"] //h1[@class="post-title"] | //div[@class="post-intro-title"] | //div[@class="post-meta-wrapper"]'
|
||||
resolve_internal_links = True
|
||||
INDEX = "http://www.danas.rs"
|
||||
extra_css = """
|
||||
.author{font-size: small}
|
||||
.published {font-size: small}
|
||||
@ -45,58 +44,30 @@ class Danas(BasicNewsRecipe):
|
||||
}
|
||||
|
||||
feeds = [
|
||||
(u'Politika', u'http://www.danas.rs/politika.56.html'),
|
||||
(u'Drustvo', u'http://www.danas.rs/drustvo.55.html'),
|
||||
(u'Dijalog', u'http://www.danas.rs/dijalog.46.html'),
|
||||
(u'Drustvo', u'http://www.danas.rs/drustvo.55.html'),
|
||||
(u'Ekonomija', u'http://www.danas.rs/ekonomija.4.html'),
|
||||
(u'Svet', u'http://www.danas.rs/svet.1160.html'),
|
||||
(u'Sport', u'http://www.danas.rs/sport.18.html'),
|
||||
(u'Kultura', u'http://www.danas.rs/kultura.11.html'),
|
||||
(u'Scena', u'http://www.danas.rs/scena.561.html'),
|
||||
(u'Zivot', u'http://www.danas.rs/zivot.1140.html'),
|
||||
(u'Auto', u'http://www.danas.rs/auto.1171.html'),
|
||||
(u'IT', u'http://www.danas.rs/it.29.html'),
|
||||
(u'Ljudi', u'http://www.danas.rs/ljudi.1141.html'),
|
||||
(u'Beograd', u'http://www.danas.rs/beograd.39.html'),
|
||||
(u'Politika', u'https://www.danas.rs/rubrika/politika/feed/'),
|
||||
(u'Drustvo', u'https://www.danas.rs/rubrika/drustvo/feed/'),
|
||||
(u'Dijalog', u'https://www.danas.rs/rubrika/dijalog/feed/'),
|
||||
(u'Ekonomija', u'https://www.danas.rs/rubrika/ekonomija/feed/'),
|
||||
(u'Svet', u'https://www.danas.rs/rubrika/svet/feed/'),
|
||||
(u'Sport', u'https://www.danas.rs/rubrika/sport/feed/'),
|
||||
(u'Kultura', u'https://www.danas.rs/rubrika/kultura/feed/'),
|
||||
(u'Scena', u'https://www.danas.rs/rubrika/scena/feed/'),
|
||||
(u'Zivot', u'https://www.danas.rs/rubrika/zivot/feed/'),
|
||||
(u'Auto', u'https://www.danas.rs/rubrika/auto/feed/'),
|
||||
(u'IT', u'https://www.danas.rs/rubrika/tehnologije/feed/'),
|
||||
(u'Ljudi', u'https://www.danas.rs/rubrika/ljudi/feed/'),
|
||||
(u'Beograd', u'https://www.danas.rs/rubrika/beograd/feed/'),
|
||||
(u'Famozno', u'https://www.danas.rs/kolumnista/svetislav-basara/feed/'),
|
||||
]
|
||||
|
||||
def get_cover_url(self):
|
||||
td = date.today() - timedelta(1)
|
||||
cpart = str(td.year) + '/' + str(td.month) + '/' + str(td.day)
|
||||
return 'http://www.danas.rs/upload/images/' + cpart + '/Naslovna_velika.jpg'
|
||||
|
||||
def parse_index(self):
|
||||
totalfeeds = []
|
||||
lfeeds = self.get_feeds()
|
||||
for feedobj in lfeeds:
|
||||
feedtitle, feedurl = feedobj
|
||||
self.report_progress(
|
||||
0,
|
||||
_('Fetching feed') + ' %s...' %
|
||||
(feedtitle if feedtitle else feedurl)
|
||||
)
|
||||
articles = []
|
||||
soup = self.index_to_soup(feedurl)
|
||||
for item in soup.findAll(
|
||||
'div', attrs={
|
||||
'class': lambda x: x and 'newsBox' in x.split()
|
||||
}
|
||||
):
|
||||
atag = item.find('h2').a
|
||||
ptag = item.find('p', attrs={'class': 'lead'})
|
||||
artdate = item.find('div', attrs={'class': 'date'})
|
||||
url = self.INDEX + atag['href']
|
||||
title = self.tag_to_string(atag)
|
||||
description = ''
|
||||
if ptag:
|
||||
description = self.tag_to_string(ptag)
|
||||
date = self.tag_to_string(artdate)
|
||||
articles.append({
|
||||
'title': title,
|
||||
'date': date,
|
||||
'url': url,
|
||||
'description': description
|
||||
})
|
||||
totalfeeds.append((feedtitle, articles))
|
||||
return totalfeeds
|
||||
months = ['januar', 'februar', 'mart', 'april', 'maj', 'jun', 'jul',
|
||||
'avgust', 'septembar', 'oktobar', 'novembar', 'decembar']
|
||||
td = date.today()
|
||||
monthname = months[td.month - 1]
|
||||
lurl = td.strftime("https://www.danas.rs/naslovna/naslovna-strana-za-%d-" + monthname + "-%Y/")
|
||||
soup = self.index_to_soup(lurl)
|
||||
al = soup.find('div', attrs={'class':'corax-image'})
|
||||
if al and al.img:
|
||||
return al.img['src']
|
||||
return None
|
||||
|
Loading…
x
Reference in New Issue
Block a user