| 1 |
from calibre.web.feeds.recipes import BasicNewsRecipe |
| 2 |
|
| 3 |
|
| 4 |
class NYTimes(BasicNewsRecipe): |
| 5 |
title = 'Focus' |
| 6 |
__author__ = 'Krittika Goyal' |
| 7 |
language = 'pl' |
| 8 |
description = 'Polish scientific monthly magazine' |
| 9 |
timefmt = ' [%d %b, %Y]' |
| 10 |
needs_subscription = False |
| 11 |
|
| 12 |
no_stylesheets = True |
| 13 |
keep_only_tags = dict(name='article', attrs={'class': 'content'}) |
| 14 |
remove_tags_after = dict(name='div', attrs={'class': 'inner_article'}) |
| 15 |
remove_tags = [ |
| 16 |
dict(name='div', attrs={'class': ['social_btns']}), |
| 17 |
] |
| 18 |
|
| 19 |
# TO GET ARTICLE TOC |
| 20 |
def nejm_get_index(self): |
| 21 |
return self.index_to_soup('http://www.focus.pl/') |
| 22 |
|
| 23 |
# To parse article toc |
| 24 |
def parse_index(self): |
| 25 |
soup = self.nejm_get_index() |
| 26 |
|
| 27 |
toc = soup.find('div', id='wrapper') |
| 28 |
|
| 29 |
articles = [] |
| 30 |
feeds = [] |
| 31 |
section_title = 'Focus Articles' |
| 32 |
for x in toc.findAll(True): |
| 33 |
if x.name == 'h1': |
| 34 |
# Article found |
| 35 |
a = x.find('a') |
| 36 |
if a is None: |
| 37 |
continue |
| 38 |
title = self.tag_to_string(a) |
| 39 |
url = a.get('href', False) |
| 40 |
if not url or not title: |
| 41 |
continue |
| 42 |
# if url.startswith('story'): |
| 43 |
url = 'http://www.focus.pl' + url |
| 44 |
self.log('\t\tFound article:', title) |
| 45 |
self.log('\t\t\t', url) |
| 46 |
articles.append({'title': title, 'url': url, 'description': '', 'date': ''}) |
| 47 |
feeds.append((section_title, articles)) |
| 48 |
|
| 49 |
return feeds |