| 1 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 2 |
|
| 3 |
try: |
| 4 |
from urllib.parse import quote |
| 5 |
except ImportError: |
| 6 |
from urllib import quote |
| 7 |
|
| 8 |
|
| 9 |
class EconomiaMagazine(BasicNewsRecipe): |
| 10 |
title = 'Economia Magazine' |
| 11 |
__author__ = 'Kovid Goyal' |
| 12 |
description = 'Economia - Intelligence & Insight for ICAEW Members' |
| 13 |
language = 'en_GB' |
| 14 |
BASE = 'http://economia.icaew.com/' |
| 15 |
no_stylesheets = True |
| 16 |
|
| 17 |
keep_only_tags = [ |
| 18 |
dict(name='h1'), |
| 19 |
dict(name='figure', attrs={'class': lambda x: x and 'figure' in x.split()}), |
| 20 |
dict(attrs={'class': 'intro articleCopy'.split()}), |
| 21 |
] |
| 22 |
|
| 23 |
def image_url_processor(cls, baseurl, iurl): |
| 24 |
if iurl: |
| 25 |
return baseurl + quote(iurl) |
| 26 |
return baseurl + '404.jpeg' |
| 27 |
|
| 28 |
def preprocess_raw_html(self, raw_html, url): |
| 29 |
return raw_html.replace('src=""', '') |
| 30 |
|
| 31 |
def parse_index(self): |
| 32 |
soup = self.index_to_soup('http://economia.icaew.com/') |
| 33 |
img = soup.find('img', src=lambda x: x and 'Magazine covers' in x) |
| 34 |
self.cover_url = self.BASE + quote(img['src'].encode('utf-8')) |
| 35 |
soup = self.index_to_soup(self.BASE + img.parent['href']) |
| 36 |
self.timefmt = ' [%s]' % self.tag_to_string(soup.find('title')).split('|')[0].strip() |
| 37 |
ans = [] |
| 38 |
for div in soup.findAll('div', attrs={'class': 'articlePreview'}): |
| 39 |
h2 = div.find('h2') |
| 40 |
section_title = self.tag_to_string(h2).strip() |
| 41 |
self.log('Found section:', section_title) |
| 42 |
articles = [] |
| 43 |
for li in div.findAll('li'): |
| 44 |
h3 = li.find('h3') |
| 45 |
title = self.tag_to_string(h3) |
| 46 |
a = h3.find('a', href=True) |
| 47 |
url = self.BASE + a['href'] |
| 48 |
p = li.find('p') |
| 49 |
self.log('\t', title, 'at', url) |
| 50 |
articles.append({'title': title, 'url': url, 'description': self.tag_to_string(p)}) |
| 51 |
if articles: |
| 52 |
ans.append((section_title, articles)) |
| 53 |
return ans |