| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
# |
| 4 |
# Copyright 2014 - 2017 Martin Račák <[email protected]> |
| 5 |
# Copyright 2011 Miroslav Vasko <[email protected]> |
| 6 |
# |
| 7 |
# This program is free software: you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation, either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
|
| 12 |
# This program is distributed in the hope that it will be useful, |
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
|
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
import re |
| 21 |
|
| 22 |
from calibre import strftime |
| 23 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 24 |
|
| 25 |
__copyright__ = '2014 - 2017 Martin Račák <[email protected]>,2011 Miroslav Vasko <[email protected]>' |
| 26 |
__license__ = 'GPL-3.0+' |
| 27 |
|
| 28 |
|
| 29 |
class Tyzden(BasicNewsRecipe): |
| 30 |
title = '.týždeň' |
| 31 |
__author__ = 'Martin Račák, zemiak' |
| 32 |
description = 'Politicko-spoločenský týždenník.' |
| 33 |
publisher = 'www.tyzden.sk' |
| 34 |
publication_type = 'magazine' |
| 35 |
language = 'sk' |
| 36 |
needs_subscription = 'optional' |
| 37 |
use_embedded_content = False |
| 38 |
no_stylesheets = True |
| 39 |
issue_url = 'http://www.tyzden.sk/casopis/' |
| 40 |
|
| 41 |
keep_only_tags = [ |
| 42 |
{'name': 'div', 'attrs': {'class': 'section__content section__content--archive'}}, |
| 43 |
{'name': 'article', 'attrs': {'class': re.compile(r'\barticle\b')}}, |
| 44 |
] |
| 45 |
|
| 46 |
extra_css = '''.theme-highlight { |
| 47 |
color: #999; |
| 48 |
text-decoration: none; |
| 49 |
} |
| 50 |
|
| 51 |
.author-highlight { |
| 52 |
color: #bf1f10; |
| 53 |
text-decoration: none; |
| 54 |
} |
| 55 |
|
| 56 |
.article__content h2::before { |
| 57 |
content: '.'; |
| 58 |
display: inline; |
| 59 |
} |
| 60 |
|
| 61 |
.article__image-credit, |
| 62 |
.content-photo__image-credit { |
| 63 |
display: block; |
| 64 |
font: 12px "TheSerifSemiLight", arial; |
| 65 |
text-transform: uppercase; |
| 66 |
} |
| 67 |
|
| 68 |
.article__image-title, |
| 69 |
.image-title { |
| 70 |
padding-top: 2px; |
| 71 |
padding-bottom: 2px; |
| 72 |
margin: 0; |
| 73 |
font: 15px "TheSerifBold", arial; |
| 74 |
border-bottom: 2px solid #bf1f10; |
| 75 |
display: block; |
| 76 |
} |
| 77 |
|
| 78 |
.teaser__title { |
| 79 |
font: 18px "TheSerifBold", arial; |
| 80 |
color: #bf1f10; |
| 81 |
} |
| 82 |
|
| 83 |
.teaser__title .highlight { |
| 84 |
color: #000; |
| 85 |
} |
| 86 |
''' |
| 87 |
|
| 88 |
def get_browser(self): |
| 89 |
br = BasicNewsRecipe.get_browser(self) |
| 90 |
if self.username is not None and self.password is not None: |
| 91 |
br.open('https://crm.tyzden.sk/sign/in/') |
| 92 |
br.select_form(nr=0) |
| 93 |
br['username'] = self.username |
| 94 |
br['password'] = self.password |
| 95 |
br.submit() |
| 96 |
return br |
| 97 |
|
| 98 |
def parse_index(self): |
| 99 |
soup = self.index_to_soup(self.issue_url) |
| 100 |
cover_img = soup.findAll('img', 'teaser__image')[-1] |
| 101 |
if cover_img is not None: |
| 102 |
self.cover_url = cover_img['src'] |
| 103 |
|
| 104 |
feeds = [] |
| 105 |
teasers = soup.findAll('div', {'class': re.compile(r'\bteaser--list\b')}) |
| 106 |
for teaser in teasers: |
| 107 |
section = self.tag_to_string(teaser.find('a', 'theme-heading__wrapper')) |
| 108 |
article_title = self.tag_to_string(teaser.find('h1', {'class': re.compile(r'\bteaser__title\b')})) |
| 109 |
article_link = teaser.find('a', 'teaser__link--main') |
| 110 |
article = {'title': article_title, 'url': article_link['href'], 'date': strftime(' %a, %d %b')} |
| 111 |
|
| 112 |
if not feeds: |
| 113 |
# First iteration. |
| 114 |
feeds.append((section, [article])) |
| 115 |
continue |
| 116 |
|
| 117 |
last_section, last_articles = feeds[-1] |
| 118 |
if section == last_section: |
| 119 |
last_articles.append(article) |
| 120 |
else: |
| 121 |
feeds.append((section, [article])) |
| 122 |
|
| 123 |
return feeds |