| 1 |
__license__ = 'GPL v3' |
| 2 |
__copyright__ = '2009-2010, Darko Miletic <darko.miletic at gmail.com>' |
| 3 |
''' |
| 4 |
spectator.org |
| 5 |
''' |
| 6 |
|
| 7 |
from css_selectors import Select |
| 8 |
|
| 9 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 10 |
|
| 11 |
|
| 12 |
class TheAmericanSpectator(BasicNewsRecipe): |
| 13 |
title = 'The American Spectator' |
| 14 |
__author__ = 'Kovid Goyal' |
| 15 |
description = 'News from USA' |
| 16 |
oldest_article = 7 |
| 17 |
max_articles_per_feed = 100 |
| 18 |
no_stylesheets = True |
| 19 |
use_embedded_content = False |
| 20 |
language = 'en_US' |
| 21 |
auto_cleanup = True |
| 22 |
encoding = 'utf-8' |
| 23 |
|
| 24 |
def parse_index(self): |
| 25 |
root = self.index_to_soup('http://spectator.org/issues/current', as_tree=True) |
| 26 |
select = Select(root) |
| 27 |
main = tuple(select('div#block-system-main'))[0] |
| 28 |
feeds = [] |
| 29 |
for div in select('div.item-list', main): |
| 30 |
for h3 in div.xpath('./h3'): |
| 31 |
section_title = self.tag_to_string(h3) |
| 32 |
self.log('\n' + section_title) |
| 33 |
break |
| 34 |
else: |
| 35 |
continue |
| 36 |
articles = [] |
| 37 |
for li in div.xpath('descendant::li'): |
| 38 |
for x in select('div.views-field-title', li): |
| 39 |
title = self.tag_to_string(x) |
| 40 |
break |
| 41 |
else: |
| 42 |
raise ValueError('No article title found') |
| 43 |
url = 'http://spectator.org' + li.xpath('./a/@href')[0] |
| 44 |
desc = '' |
| 45 |
for x in select('div.views-field-field-short-summary', li): |
| 46 |
desc = self.tag_to_string(x) |
| 47 |
break |
| 48 |
articles.append({'title': title, 'url': url, 'description': desc}) |
| 49 |
self.log('\t', title, 'at', url) |
| 50 |
feeds.append((section_title, articles)) |
| 51 |
return feeds |