forked from kovidgoyal/calibre
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathap.recipe
More file actions
50 lines (42 loc) · 1.68 KB
/
Copy pathap.recipe
File metadata and controls
50 lines (42 loc) · 1.68 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
from calibre.web.feeds.news import BasicNewsRecipe
class AssociatedPress(BasicNewsRecipe):
title = u'Associated Press'
description = 'Global news'
__author__ = 'Krittika Goyal'
use_embedded_content = False
language = 'en'
no_stylesheets = True
conversion_options = {
'linearize_tables': True
}
keep_only_tags = {'name': 'table', 'attrs': {
'class': lambda x: x and 'ap-story-table' in x.split()}}
remove_tags = [
{'class': ['ap-mediabox-table']},
{'name': 'img', 'src': lambda x: x and '//analytics.' in x},
]
def parse_index(self):
feeds = []
fronts = ('HOME', 'US', 'WORLD', 'BUSINESS', 'TECHNOLOGY',
'SPORTS', 'ENTERTAINMENT', 'HEALTH', 'SCIENCE', 'POLITICS')
for front in fronts:
feeds.append([front.capitalize(), self.parse_section(front)])
feeds[0][0] = 'Top Stories'
return feeds
def parse_section(self, front):
self.log('Processing section:', front)
soup = self.index_to_soup(
'http://hosted.ap.org/dynamic/fronts/%s?SITE=AP' % front)
articles = []
for x in soup.findAll('p', attrs={'class': ['ap-newsbriefitem-p', 'ap-topheadlineitem-p']}):
a = x.find('a', href=True)
title = self.tag_to_string(a)
url = "http://hosted.ap.org" + a['href']
p = x.find(attrs={'class': 'topheadlinebody'})
desc = ''
if p is not None:
desc = self.tag_to_string(p)
self.log('\tFound article:', title, '\n\t\t', desc)
articles.append({'title': title, 'url': url})
self.log('\n\n')
return articles