mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-30 23:00:21 -04:00
Dnevnik (MK) and =Info by Darko Spasovski
This commit is contained in:
parent
9618a0ac4d
commit
6557e06577
98
recipes/dnevnik_mk.recipe
Normal file
98
recipes/dnevnik_mk.recipe
Normal file
@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
__author__ = 'Darko Spasovski'
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2011, Darko Spasovski <darko.spasovski at gmail.com>'
|
||||
'''
|
||||
dnevnik.com.mk
|
||||
'''
|
||||
|
||||
import re
|
||||
import datetime
|
||||
from calibre.web.feeds.news import BasicNewsRecipe
|
||||
from calibre import browser
|
||||
from calibre.ebooks.BeautifulSoup import BeautifulSoup
|
||||
|
||||
class Dnevnik(BasicNewsRecipe):
|
||||
|
||||
INDEX = 'http://www.dnevnik.com.mk'
|
||||
__author__ = 'Darko Spasovski'
|
||||
title = 'Dnevnik - mk'
|
||||
description = 'Daily Macedonian newspaper'
|
||||
masthead_url = 'http://www.dnevnik.com.mk/images/re-logo.gif'
|
||||
language = 'mk'
|
||||
publication_type = 'newspaper'
|
||||
category = 'news, Macedonia'
|
||||
max_articles_per_feed = 100
|
||||
remove_javascript = True
|
||||
no_stylesheets = True
|
||||
use_embedded_content = False
|
||||
|
||||
preprocess_regexps = [(re.compile(i[0], re.IGNORECASE | re.DOTALL), i[1]) for i in
|
||||
[
|
||||
## Remove anything before the start of the article.
|
||||
(r'<body.*?<\?xml version=\"1.0\"\?><!--Article start-->', lambda match: '<body>'),
|
||||
|
||||
## Remove anything after the end of the article.
|
||||
(r'<!--Article end.*?</body>', lambda match : '</body>'),
|
||||
]
|
||||
]
|
||||
|
||||
extra_css = """
|
||||
body{font-family: Arial,Helvetica,sans-serif}
|
||||
.WB_DNEVNIK_Naslov{FONT-WEIGHT: bold; FONT-SIZE: 18px; FONT-FAMILY: Arial, Verdana, Tahoma; TEXT-DECORATION: none}
|
||||
"""
|
||||
|
||||
conversion_options = {
|
||||
'comment' : description,
|
||||
'tags' : category,
|
||||
'language' : language,
|
||||
'linearize_tables' : True
|
||||
}
|
||||
|
||||
def parse_index(self):
|
||||
datum = datetime.datetime.today().strftime('%d.%m.%Y')
|
||||
soup = self.index_to_soup(self.INDEX + '/default.asp?section=arhiva&arhDatum=' + datum)
|
||||
feeds = []
|
||||
for section in soup.findAll('td', attrs={'class':'WB_DNEVNIK_ArhivaFormTitle'}):
|
||||
sectionTitle = section.contents[0].string
|
||||
if sectionTitle.lower().startswith('online'):
|
||||
# Skip online articles
|
||||
continue
|
||||
containerTable = section.findPrevious(name='table').findNextSibling(name='table')
|
||||
if containerTable==None:
|
||||
print 'No container table found - page layout may have been changed.'
|
||||
continue
|
||||
articles = []
|
||||
for article in containerTable.findAll('a', attrs={'class': 'WB_DNEVNIK_ArhivaFormText'}):
|
||||
title = self.tag_to_string(article, use_alt=True).strip()
|
||||
articles.append({'title': title, 'url':'http://www.dnevnik.com.mk/' + article['href'], 'description':'', 'date':''})
|
||||
if articles:
|
||||
feeds.append((sectionTitle, articles))
|
||||
return sorted(feeds, key=lambda section: self.get_weight(section))
|
||||
|
||||
def get_weight(self, section):
|
||||
"""
|
||||
Returns 'weight' of a section.
|
||||
Used for sorting the sections based on their 'natural' order in the printed edition.
|
||||
"""
|
||||
natural_order = { u'во фокусот': 1, u'актуелно': 2, u'економија': 3,
|
||||
u'отворена': 4, u'свет': 5, u'интервју': 6, u'џубокс': 7,
|
||||
u'репортажа': 8, u'наш туризам': 9, u'живот': 10,
|
||||
u'автомобилизам': 11, u'спорт': 12, u'омнибус': 13 }
|
||||
if section[0].string.lower() in natural_order:
|
||||
return natural_order[section[0].string.lower()]
|
||||
else:
|
||||
return 999 # section names not on the list go to the bottom
|
||||
|
||||
def get_cover_url(self):
|
||||
datum = datetime.datetime.today().strftime('%d.%m.%Y')
|
||||
soup = self.index_to_soup(self.INDEX + '/default.asp?section=arhiva&arhDatum=' + datum)
|
||||
anchor = soup.find('a', attrs={'class': 'WB_DNEVNIK_MoreLink'})
|
||||
if anchor != None:
|
||||
raw = browser().open_novisit(self.INDEX + '/' + anchor['href']).read()
|
||||
cover_soup = BeautifulSoup(raw)
|
||||
url = cover_soup.find('div', attrs={'class':'WB_DNEVNIK_Datum2'}).findNext('img')['src']
|
||||
return self.INDEX + '/' + url
|
||||
return ''
|
||||
|
47
recipes/plus_info.recipe
Normal file
47
recipes/plus_info.recipe
Normal file
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
__author__ = 'Darko Spasovski'
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2011, Darko Spasovski <darko.spasovski at gmail.com>'
|
||||
|
||||
'''
|
||||
www.plusinfo.mk
|
||||
'''
|
||||
|
||||
from calibre.web.feeds.news import BasicNewsRecipe
|
||||
|
||||
class PlusInfo(BasicNewsRecipe):
|
||||
|
||||
INDEX = 'www.plusinfo.mk'
|
||||
title = u'+info'
|
||||
__author__ = 'Darko Spasovski'
|
||||
description = 'Macedonian news portal'
|
||||
publication_type = 'newsportal'
|
||||
category = 'news, Macedonia'
|
||||
language = 'mk'
|
||||
masthead_url = 'http://www.plusinfo.mk/style/images/logo.jpg'
|
||||
remove_javascript = True
|
||||
no_stylesheets = True
|
||||
use_embedded_content = False
|
||||
remove_empty_feeds = True
|
||||
oldest_article = 1
|
||||
max_articles_per_feed = 100
|
||||
|
||||
keep_only_tags = [dict(name='div', attrs={'class': 'vest'})]
|
||||
remove_tags = [dict(name='div', attrs={'class':['komentari_holder', 'objava']})]
|
||||
|
||||
feeds = [(u'Македонија', u'http://www.plusinfo.mk/rss/makedonija'),
|
||||
(u'Бизнис', u'http://www.plusinfo.mk/rss/biznis'),
|
||||
(u'Скопје', u'http://www.plusinfo.mk/rss/skopje'),
|
||||
(u'Култура', u'http://www.plusinfo.mk/rss/kultura'),
|
||||
(u'Свет', u'http://www.plusinfo.mk/rss/svet'),
|
||||
(u'Сцена', u'http://www.plusinfo.mk/rss/scena'),
|
||||
(u'Здравје', u'http://www.plusinfo.mk/rss/zdravje'),
|
||||
(u'Магазин', u'http://www.plusinfo.mk/rss/magazin'),
|
||||
(u'Спорт', u'http://www.plusinfo.mk/rss/sport')]
|
||||
|
||||
# uncomment the following block if you want the print version (note: it lacks photos)
|
||||
# def print_version(self,url):
|
||||
# segments = url.split('/')
|
||||
# printURL = '/'.join(segments[0:3]) + '/print/' + '/'.join(segments[5:])
|
||||
# return printURL
|
Loading…
x
Reference in New Issue
Block a user