Debian Codegraph @

recipes/high_country_news.recipe

raw
1 # -*- coding: utf-8 -*-
2
3 __license__ = 'GPL v3'
4 __copyright__ = '2013, Armin Geller'
5 '''
6 Fetch High Country News
7 '''
8 from calibre.web.feeds.news import BasicNewsRecipe
9
10
11 class HighCountryNews(BasicNewsRecipe):
12 ##
13 # Written: 2012-01-28
14 # Last Edited: 2023-06-30
15 #
16 # Remark: Version 2.3
17 # Update language to fix how it appears in UI tree
18 # Version 2.2
19 # Update RSS feeds to hcn.org and keep the old feedburner feeds still in place
20 # as there are some old articles available only at feedburner address
21 # 2019-07-04
22 # Version 2.3
23 # New Page design at HighCountryNews
24 # 2020-12-29
25 # Version 2.4
26 # Page design updates at HighCountryNews
27 # 2021-01-11
28 # Version 2.5a
29 # Again changes in page design
30 # 2021-01-12
31 # Version 2.5b
32 # test old feeds availability and check for new feeds
33 # 2022-08-17
34 # Version 2.6
35 # css changes, some cleanup
36 #
37
38 title = 'High Country News'
39 description = 'High Country News (RSS Version)'
40 __author__ = 'Armin Geller'
41 publisher = 'High Country News'
42 category = 'News, Politics, Social, Nature, Environmental, Western United States, Native American'
43 timefmt = ' [%a, %d %b %Y]'
44 language = 'en'
45 encoding = 'UTF-8'
46 publication_type = 'newspaper'
47 oldest_article = 30
48 max_articles_per_feed = 100
49 no_stylesheets = True
50 auto_cleanup = False
51 remove_javascript = True
52 remove_empty_feeds = True
53 remove_attributes = ['style', 'width', 'height']
54 use_embedded_content = False
55
56 masthead_url = 'http://www.hcn.org/logo.jpg'
57 cover_source = 'http://www.hcn.org/issues'
58
59 def get_cover_url(self):
60 cover_source_soup = self.index_to_soup(self.cover_source)
61 preview_image_div = cover_source_soup.find(attrs={'class': 'articles'}) # AGE 2014-09-18 new
62 return preview_image_div.div.a.figure.img['src'] # AGE 2014-09-18 newm take always the first one (hopefully)
63
64 # AGe new extra css to get rid of ugly style
65 # li for delete disc style,
66 # caption and credit for description & author of pictures
67 # main-topic
68
69 extra_css = '''
70 h1 {font-size: 1.6em; text-align: left}
71 h2 {font-size: 1em; font-style: italic; font-weight: normal}
72 h3 {font-size: 1.3em;text-align: left}
73 h4, h5, h6, {font-size: 1em;text-align: left}
74 li {list-style-type: none; Font-size: 1.0em}
75 .caption, .credit {font-size: 0.9em; font-style: italic}
76 .pullquote {font-size: 1.1em; font-weight: bold; font-style: italic}
77 .main-topic {font-size: 0.85em; font-weight: bold}
78 '''
79
80 feeds = [
81 ('Most Recent', 'https://www.hcn.org/rss/most-recent/rss.xml'), # AGE 2019-07-04 new
82 ('Current Issue', 'https://www.hcn.org/rss/current-issue/rss.xml'), # AGE 2019-07-04 new
83 ('The Range blog', 'http://cdn.hcn.org/rss/range/RSS'), # AGE 2021-01-13 still available with old entries
84 ('Features', 'https://www.hcn.org/rss/features/rss.xml'), # AGE 2021-01-13
85 ('Ranch Diaries', 'https://www.hcn.org/voices/ranchdiaries/RSS'), # AGE 2021-01-13
86 ('Writers on the Range', 'https://www.hcn.org/rss/wotr/rss.xml'), # AGE 2019-07-04 new
87 ('West Obsessed', 'https://feeds.soundcloud.com/users/soundcloud:users:299947441/sounds.rss'), # AGE 2016-12-04 new
88 # (u'The Range', u'http://feeds.feedburner.com/hcn/range?format=xml'), # AGE 2016-12-04 old feedburner
89 ('From the Blogs', 'http://feeds.feedburner.com/hcn/FromTheBlogs?format=xml'),
90 ('Heard around the West', 'http://feeds.feedburner.com/hcn/heard?format=xml'),
91 ('The GOAT Blog', 'http://feeds.feedburner.com/hcn/goat?format=xml'),
92 ('High Country Views', 'http://feeds.feedburner.com/hcn/HighCountryViews'),
93 ]
94
95 keep_only_tags = [
96 dict(name='div', attrs={'id': 'content'}),
97 dict(name='div', attrs={'class': 'opaque'}),
98 dict(name='div', attrs={'id': 'main'}),
99 dict(name='div', attrs={'class': ['row feature-row', 'small-12 columns', 'intro', 'dropcap']}),
100 ]
101
102 remove_tags = [
103 dict(
104 name='div',
105 attrs={
106 'class': [
107 'large-4 columns right-portlets',
108 'pagination-share',
109 'large highlight newsletter-signup button',
110 'newsletter-signup portlet',
111 'document-actions',
112 ]
113 },
114 ),
115 dict(
116 name='ul',
117 attrs={
118 'class': [
119 'topics',
120 ]
121 },
122 ),
123 dict(
124 name='dl',
125 attrs={
126 'id': [
127 'kssPortalMessage',
128 ]
129 },
130 ),
131 ]
132
133 # AGE 2014-09-18 this will stay for a while
134 # but have no impact for now ...
135
136 INDEX = ''
137
138 def append_page(self, soup, appendtag, position):
139 pager = soup.find('span', attrs={'class': 'next'})
140 if pager:
141 nexturl = self.INDEX + pager.a['href']
142 soup2 = self.index_to_soup(nexturl)
143 texttag = soup2.find('div', attrs={'class': 'article-text'})
144 newpos = len(texttag.contents)
145 self.append_page(soup2, texttag, newpos)
146 texttag.extract()
147 appendtag.insert(position, texttag)
148
149 def preprocess_html(self, soup):
150 self.append_page(soup, soup.body, 3)
151 pager = soup.find('div', attrs={'class': 'listingBar listingBar-article'})
152 if pager:
153 pager.extract()
154 return self.adeify_images(soup)