mirror of
git://github.com/kovidgoyal/calibre.git
synced 2025-12-25 14:24:26 +01:00
41 lines
1.4 KiB
Text
41 lines
1.4 KiB
Text
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
|
|
auto_cleanup = True
|
|
auto_cleanup_keep = '//tr[@class="ap-story-td"]'
|
|
|
|
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
|