mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update Danas
Fixes #1742163 [Updated recipe for Danas](https://bugs.launchpad.net/calibre/+bug/1742163) [Updated recipe for Danas](https://bugs.launchpad.net/calibre/+bug/1742163)
This commit is contained in:
parent
585cce2985
commit
6250465558
@ -1,131 +1,102 @@
|
|||||||
|
# -*- mode: python -*-
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008-2011, Darko Miletic <darko.miletic at gmail.com>'
|
__copyright__ = '2008-2018, Darko Miletic <darko.miletic at gmail.com>'
|
||||||
'''
|
'''
|
||||||
danas.rs
|
danas.rs
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import re
|
|
||||||
from calibre.web.feeds.news import BasicNewsRecipe
|
from calibre.web.feeds.news import BasicNewsRecipe
|
||||||
|
from datetime import date, timedelta
|
||||||
|
|
||||||
|
|
||||||
class Danas(BasicNewsRecipe):
|
class Danas(BasicNewsRecipe):
|
||||||
title = 'Danas'
|
title = 'Danas'
|
||||||
__author__ = 'Darko Miletic'
|
__author__ = 'Darko Miletic'
|
||||||
description = 'Dnevne novine sa vestima iz sveta, politike, ekonomije, kulture, sporta, Beograda, Novog Sada i cele Srbije.'
|
description = 'Dnevne novine sa vestima iz sveta, politike, ekonomije, kulture, sporta, Beograda, Novog Sada i cele Srbije.'
|
||||||
publisher = 'Danas d.o.o.'
|
publisher = 'DAN GRAF d.o.o.'
|
||||||
category = 'news, politics, Serbia'
|
category = 'danas Dnevne novine politika drustvo ekonomija svet sport beograd vojvodina periskop terazije Beograd Srbija Novi Sad Nis Kragujevac Vojvodina politics Serbia' # noqa
|
||||||
oldest_article = 2
|
oldest_article = 2
|
||||||
max_articles_per_feed = 100
|
max_articles_per_feed = 100
|
||||||
no_stylesheets = False
|
no_stylesheets = False
|
||||||
use_embedded_content = False
|
use_embedded_content = False
|
||||||
encoding = 'utf-8'
|
encoding = 'utf-8'
|
||||||
masthead_url = 'http://www.danas.rs/images/basic/danas.gif'
|
masthead_url = 'http://www.danas.rs/images/basic/logo.png'
|
||||||
language = 'sr'
|
language = 'sr'
|
||||||
remove_javascript = True
|
remove_javascript = True
|
||||||
publication_type = 'newspaper'
|
publication_type = 'newspaper'
|
||||||
remove_empty_feeds = True
|
remove_empty_feeds = True
|
||||||
extra_css = """ @font-face {font-family: "serif1";src:url(res:///opt/sony/ebook/FONT/tt0011m_.ttf)}
|
auto_cleanup = True
|
||||||
@font-face {font-family: "sans1";src:url(res:///opt/sony/ebook/FONT/tt0003m_.ttf)}
|
auto_cleanup_keep = '//h1[@class="title"] | //div[@class="subTitle"] | //div[@class="author"] | //div[@class="published"]'
|
||||||
.article,.articledescription,body,.lokacija,.feed{font-family: Tahoma,Arial,Helvetica,sans1,sans-serif}
|
resolve_internal_links = True
|
||||||
.nadNaslov,h1,.preamble{font-family: Georgia,"Times New Roman",Times,serif1,serif}
|
INDEX = "http://www.danas.rs"
|
||||||
.antrfileText{border-left: 2px solid #999999;
|
extra_css = """
|
||||||
margin-left: 0.8em;
|
.author{font-size: small}
|
||||||
padding-left: 1.2em;
|
.published {font-size: small}
|
||||||
margin-bottom: 0;
|
|
||||||
margin-top: 0}
|
|
||||||
h2,.datum,.lokacija,.autor{font-size: small}
|
|
||||||
.autor{text-transform: uppercase}
|
|
||||||
.antrfileNaslov{border-left: 2px solid #999999;
|
|
||||||
margin-left: 0.8em;
|
|
||||||
padding-left: 1.2em;
|
|
||||||
font-weight:bold;
|
|
||||||
margin-bottom: 0;
|
|
||||||
margin-top: 0}
|
|
||||||
img{margin-bottom: 0.8em}
|
img{margin-bottom: 0.8em}
|
||||||
.naslovTemeDana{font-size: small}
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
conversion_options = {
|
conversion_options = {
|
||||||
'comment': description, 'tags': category, 'publisher': publisher, 'language': language
|
'comment': description,
|
||||||
|
'tags': category,
|
||||||
|
'publisher': publisher,
|
||||||
|
'language': language
|
||||||
}
|
}
|
||||||
|
|
||||||
preprocess_regexps = [
|
|
||||||
(re.compile(u'\u0110'), lambda match: u'\u00D0'), (re.compile(
|
|
||||||
u'\u2018'), lambda match: '‘') # left single quotation mark
|
|
||||||
# right single quotation mark
|
|
||||||
# single low-9 quotation mark
|
|
||||||
# single high-reversed-9 quotation mark
|
|
||||||
# left double quotation mark
|
|
||||||
# right double quotation mark
|
|
||||||
# double low-9 quotation mark
|
|
||||||
# double high-reversed-9 quotation mark
|
|
||||||
# latin small letter o with circumflex
|
|
||||||
# latin small letter o with dieaeresis
|
|
||||||
# latin small letter a with acute
|
|
||||||
# latin small letter a with dieaeresis
|
|
||||||
, (re.compile(u'\u2019'), lambda match: '’'), (re.compile(u'\u201a'), lambda match: '‘'), (re.compile(u'\u201b'), lambda match: '’'), (re.compile(u'\u201c'), lambda match: '“'), (re.compile(u'\u201d'), lambda match: '”'), (re.compile(u'\u201e'), lambda match: '“'), (re.compile(u'\u201f'), lambda match: '”'), (re.compile(u'\u00f4'), lambda match: '“'), (re.compile(u'\u00f6'), lambda match: '”'), (re.compile(u'\u00e1'), lambda match: ' '), (re.compile(u'\u00e4'), lambda match: ' ') # noqa
|
|
||||||
]
|
|
||||||
|
|
||||||
keep_only_tags = [dict(name='div', attrs={'id': 'left'})]
|
|
||||||
remove_tags = [
|
|
||||||
dict(name='div', attrs={'class': ['width_1_4', 'metaClanka', 'baner', 'listaVesti', 'article_nav']}), dict(
|
|
||||||
name='div', attrs={'id': 'comments'}), dict(name=['object', 'link', 'iframe', 'meta'])
|
|
||||||
]
|
|
||||||
remove_attributes = ['w:st', 'st']
|
|
||||||
|
|
||||||
feeds = [
|
feeds = [
|
||||||
|
(u'Politika', u'http://www.danas.rs/politika.56.html'),
|
||||||
(u'Politika', u'http://www.danas.rs/rss/rss.asp?column_id=27'),
|
(u'Drustvo', u'http://www.danas.rs/drustvo.55.html'),
|
||||||
(u'Hronika', u'http://www.danas.rs/rss/rss.asp?column_id=2'),
|
(u'Dijalog', u'http://www.danas.rs/dijalog.46.html'),
|
||||||
(u'Drustvo', u'http://www.danas.rs/rss/rss.asp?column_id=24'),
|
(u'Drustvo', u'http://www.danas.rs/drustvo.55.html'),
|
||||||
(u'Dijalog', u'http://www.danas.rs/rss/rss.asp?column_id=1'),
|
(u'Ekonomija', u'http://www.danas.rs/ekonomija.4.html'),
|
||||||
(u'Ekonomija', u'http://www.danas.rs/rss/rss.asp?column_id=6'),
|
(u'Svet', u'http://www.danas.rs/svet.1160.html'),
|
||||||
(u'Svet', u'http://www.danas.rs/rss/rss.asp?column_id=25'),
|
(u'Sport', u'http://www.danas.rs/sport.18.html'),
|
||||||
(u'Srbija', u'http://www.danas.rs/rss/rss.asp?column_id=28'),
|
(u'Kultura', u'http://www.danas.rs/kultura.11.html'),
|
||||||
(u'Kultura', u'http://www.danas.rs/rss/rss.asp?column_id=5'),
|
(u'Scena', u'http://www.danas.rs/scena.561.html'),
|
||||||
(u'Sport', u'http://www.danas.rs/rss/rss.asp?column_id=13'),
|
(u'Zivot', u'http://www.danas.rs/zivot.1140.html'),
|
||||||
(u'Scena', u'http://www.danas.rs/rss/rss.asp?column_id=42'),
|
(u'Auto', u'http://www.danas.rs/auto.1171.html'),
|
||||||
(u'Feljton', u'http://www.danas.rs/rss/rss.asp?column_id=19'),
|
(u'IT', u'http://www.danas.rs/it.29.html'),
|
||||||
(u'Periskop', u'http://www.danas.rs/rss/rss.asp?column_id=4'),
|
(u'Ljudi', u'http://www.danas.rs/ljudi.1141.html'),
|
||||||
(u'Famozno', u'http://www.danas.rs/rss/rss.asp?column_id=47'),
|
(u'Beograd', u'http://www.danas.rs/beograd.39.html'),
|
||||||
(u'Sluzbena beleska', u'http://www.danas.rs/rss/rss.asp?column_id=48'),
|
|
||||||
(u'Suocavanja', u'http://www.danas.rs/rss/rss.asp?column_id=49'),
|
|
||||||
(u'Moj Izbor', u'http://www.danas.rs/rss/rss.asp?column_id=50'),
|
|
||||||
(u'Direktno', u'http://www.danas.rs/rss/rss.asp?column_id=51'),
|
|
||||||
(u'I tome slicno', u'http://www.danas.rs/rss/rss.asp?column_id=52'),
|
|
||||||
(u'No longer and not yet', u'http://www.danas.rs/rss/rss.asp?column_id=53'),
|
|
||||||
(u'Resetovanje', u'http://www.danas.rs/rss/rss.asp?column_id=54'),
|
|
||||||
(u'Iza scene', u'http://www.danas.rs/rss/rss.asp?column_id=60'),
|
|
||||||
(u'Drustvoslovlje', u'http://www.danas.rs/rss/rss.asp?column_id=55'),
|
|
||||||
(u'Zvaka u pepeljari', u'http://www.danas.rs/rss/rss.asp?column_id=56'),
|
|
||||||
(u'Vostani Serbie', u'http://www.danas.rs/rss/rss.asp?column_id=57'),
|
|
||||||
(u'Med&Jad-a', u'http://www.danas.rs/rss/rss.asp?column_id=58'),
|
|
||||||
(u'Svetlosti pozornice', u'http://www.danas.rs/rss/rss.asp?column_id=59'),
|
|
||||||
(u'Dva cvancika', u'http://www.danas.rs/rss/rss.asp?column_id=65'),
|
|
||||||
(u'Iz kornera', u'http://www.danas.rs/rss/rss.asp?column_id=64')
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def preprocess_html(self, soup):
|
|
||||||
for tagn in ['st1:place', 'st1:city', 'st1:country-region', 'st1:state']:
|
|
||||||
for item in soup.body.findAll(tagn):
|
|
||||||
item.name = 'span'
|
|
||||||
for item in soup.findAll(style=True):
|
|
||||||
del item['style']
|
|
||||||
for item in soup.findAll('a'):
|
|
||||||
if item.has_key('name'): # noqa
|
|
||||||
item.extract()
|
|
||||||
for item in soup.findAll('img'):
|
|
||||||
if not item.has_key('alt'): # noqa
|
|
||||||
item['alt'] = 'image'
|
|
||||||
return soup
|
|
||||||
|
|
||||||
def print_version(self, url):
|
|
||||||
return url + '&action=print'
|
|
||||||
|
|
||||||
def get_cover_url(self):
|
def get_cover_url(self):
|
||||||
cover_url = None
|
td = date.today() - timedelta(1)
|
||||||
soup = self.index_to_soup('http://www.danas.rs/')
|
cpart = str(td.year) + '/' + str(td.month) + '/' + str(td.day)
|
||||||
for citem in soup.findAll('img'):
|
return 'http://www.danas.rs/upload/images/' + cpart + '/Naslovna_velika.jpg'
|
||||||
if citem['src'].endswith('naslovna.jpg') or citem['src'].endswith('naslovna1.jpg'):
|
|
||||||
return 'http://www.danas.rs' + citem['src']
|
def parse_index(self):
|
||||||
return cover_url
|
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
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 485 B After Width: | Height: | Size: 553 B |
Loading…
x
Reference in New Issue
Block a user