-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbay_citizen.recipe
46 lines (42 loc) · 1.98 KB
/
bay_citizen.recipe
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
from calibre.web.feeds.news import BasicNewsRecipe
class TheBayCitizen(BasicNewsRecipe):
title = 'The Bay Citizen'
language = 'en'
__author__ = 'noah'
description = 'The Bay Citizen'
publisher = 'The Bay Citizen'
INDEX = u'http://www.baycitizen.org'
category = 'news'
oldest_article = 2
max_articles_per_feed = 20
no_stylesheets = True
masthead_url = 'http://media.baycitizen.org/images/layout/logo1.png'
feeds = [('Main Feed', 'http://www.baycitizen.org/feeds/stories/')]
keep_only_tags = [dict(name='div', attrs={'class':'story'})]
remove_tags = [
dict(name='div', attrs={'class':'socialBar'}),
dict(name='div', attrs={'id':'text-resize'}),
dict(name='div', attrs={'class':'story relatedContent'}),
dict(name='div', attrs={'id':'comment_status_loading'}),
]
def append_page(self, soup, appendtag, position):
pager = soup.find('a',attrs={'class':'stry-next'})
if pager:
nexturl = self.INDEX + pager['href']
soup2 = self.index_to_soup(nexturl)
texttag = soup2.find('div', attrs={'class':'body'})
for it in texttag.findAll(style=True):
del it['style']
newpos = len(texttag.contents)
self.append_page(soup2,texttag,newpos)
texttag.extract()
appendtag.insert(position,texttag)
def preprocess_html(self, soup):
for item in soup.findAll(style=True):
del item['style']
self.append_page(soup, soup.body, 3)
garbage = soup.findAll(id='story-pagination')
[trash.extract() for trash in garbage]
garbage = soup.findAll('em', 'cont-from-prev')
[trash.extract() for trash in garbage]
return soup