| 1 |
#!/usr/bin/env python |
| 2 |
__author__ = 'Jordi Balcells' |
| 3 |
__license__ = 'GPL v3' |
| 4 |
description = 'Jornal portugu\xeas - v1.03 (16 June 2010)' |
| 5 |
__docformat__ = 'restructuredtext en' |
| 6 |
|
| 7 |
''' |
| 8 |
publico.pt |
| 9 |
''' |
| 10 |
|
| 11 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 12 |
from polyglot.urllib import urlencode |
| 13 |
|
| 14 |
|
| 15 |
def classes(classes): |
| 16 |
q = frozenset(classes.split(' ')) |
| 17 |
return dict(attrs={'class': lambda x: x and frozenset(x.split()).intersection(q)}) |
| 18 |
|
| 19 |
|
| 20 |
class PublicoPT(BasicNewsRecipe): |
| 21 |
description = 'Jornal portugu\xeas' |
| 22 |
cover_url = 'http://static.publico.pt/files/header/img/publico.gif' |
| 23 |
title = 'Publico.PT' |
| 24 |
category = 'News, politics, culture, economy, general interest' |
| 25 |
oldest_article = 2 |
| 26 |
no_stylesheets = True |
| 27 |
encoding = 'utf8' |
| 28 |
use_embedded_content = False |
| 29 |
language = 'pt' |
| 30 |
remove_empty_feeds = True |
| 31 |
extra_css = ' body{font-family: Arial,Helvetica,sans-serif } img{margin-bottom: 0.4em} ' |
| 32 |
needs_subscription = True |
| 33 |
|
| 34 |
keep_only_tags = [ |
| 35 |
dict(id='story-content story-header'.split()), |
| 36 |
] |
| 37 |
remove_tags = [ |
| 38 |
classes('social-tools'), |
| 39 |
] |
| 40 |
remove_attributes = ['style'] |
| 41 |
|
| 42 |
feeds = [ |
| 43 |
('Geral', 'http://feeds.feedburner.com/publicoRSS'), |
| 44 |
('Mundo', 'http://feeds.feedburner.com/PublicoMundo'), |
| 45 |
('Pol\xedtica', 'http://feeds.feedburner.com/PublicoPolitica'), |
| 46 |
('Economia', 'http://feeds.feedburner.com/PublicoEconomia'), |
| 47 |
('Desporto', 'http://feeds.feedburner.com/PublicoDesporto'), |
| 48 |
('Sociedade', 'http://feeds.feedburner.com/PublicoSociedade'), |
| 49 |
('Educa\xe7\xe3o', 'http://feeds.feedburner.com/PublicoEducacao'), |
| 50 |
('Ci\xeancias', 'http://feeds.feedburner.com/PublicoCiencias'), |
| 51 |
('Ecosfera', 'http://feeds.feedburner.com/PublicoEcosfera'), |
| 52 |
('Cultura', 'http://feeds.feedburner.com/PublicoCultura'), |
| 53 |
('Local', 'http://feeds.feedburner.com/PublicoLocal'), |
| 54 |
('Tecnologia', 'http://feeds.feedburner.com/PublicoTecnologia'), |
| 55 |
] |
| 56 |
|
| 57 |
def get_browser(self): |
| 58 |
br = BasicNewsRecipe.get_browser(self) |
| 59 |
if self.username is not None and self.password is not None: |
| 60 |
postdata = urlencode({'username': self.username, 'password': self.password}) |
| 61 |
br.open('https://www.publico.pt/api/user/login', data=postdata, timeout=self.timeout) |
| 62 |
|
| 63 |
br.set_handle_refresh(True) |
| 64 |
|
| 65 |
return br |
| 66 |
|
| 67 |
def preprocess_html(self, soup): |
| 68 |
for img in soup.findAll('img', attrs={'data-media-viewer': True}): |
| 69 |
img['src'] = img['data-media-viewer'] |
| 70 |
return soup |