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