Debian Codegraph @

recipes/ourdailybread.recipe

raw
1 __license__ = 'GPL v3'
2 __copyright__ = '2009-2010, Darko Miletic <darko.miletic at gmail.com>'
3 '''
4 odb.org
5 '''
6
7 import uuid
8
9 from lxml import html
10
11 from calibre.web.feeds.news import BasicNewsRecipe
12
13
14 class OurDailyBread(BasicNewsRecipe):
15 title = 'Our Daily Bread'
16 __author__ = 'Kovid Goyal'
17 description = "Our Daily Bread is a daily devotional from RBC Ministries which helps readers spend time each day in God's Word."
18 oldest_article = 15
19 language = 'en'
20 max_articles_per_feed = 100
21 no_stylesheets = True
22 use_embedded_content = False
23 encoding = 'utf-8'
24
25 conversion_options = {'comments': description, 'language': language, 'linearize_tables': True}
26
27 keep_only_tags = [dict(attrs={'class': 'calibre-inserted-psalm'}), {'id': 'content'}]
28 remove_tags = [
29 dict(attrs={'class': ['listen-box', 'entry-zoom', 'entry-footer']}),
30 {'id': 'nav-single'},
31 dict(attrs={'class': lambda x: x and ' sharing ' in x}),
32 ]
33
34 extra_css = '''
35 .text{font-family:Arial,Helvetica,sans-serif;font-size:x-small;}
36 .devotionalTitle{font-family:Arial,Helvetica,sans-serif; font-size:large; font-weight: bold;}
37 .devotionalDate{font-family:Arial,Helvetica,sans-serif; font-size:xx-small;}
38 .devotionalVerse{font-family:Arial,Helvetica,sans-serif; font-size:xx-small; }
39 a{color:#000000;font-family:Arial,Helvetica,sans-serif; font-size:x-small;}
40 '''
41
42 feeds = [('Our Daily Bread', 'http://odb.org/feed/')]
43
44 def preprocess_raw_html(self, raw, url):
45 # Convert links to referenced Psalms to the actual psalms
46 root = html.fromstring(raw)
47 for a in root.xpath('//a[starts-with(@href, "http://www.biblegateway.com")]'):
48 uid = type('')(uuid.uuid4())
49 raw = self.index_to_soup(a.get('href'), raw=True)
50 iroot = html.fromstring(raw)
51 matches = iroot.xpath('//div[contains(@class, "result-text-style-normal")]')
52 if matches:
53 div = matches[0]
54 div.getparent().remove(div)
55 root.xpath('//body')[0].append(div)
56 a.set('href', '#' + uid)
57 del a.attrib['target']
58 div.set('id', uid)
59 div.set('class', 'calibre-inserted-psalm')
60 hr = div.makeelement('hr')
61 div.insert(0, hr)
62 # print(html.tostring(div))
63 raw = html.tostring(root, encoding='unicode')
64 return raw
65
66 def preprocess_html(self, soup):
67 d = soup.find(id='content')
68 d.extract()
69 soup.find('body').insert(0, d)
70 return soup