@@ -20,66 +20,48 @@ class Slate(BasicNewsRecipe):
2020 title = 'Slate'
2121 description = 'A general-interest publication offering analysis and commentary about politics, news and culture.'
2222 __author__ = 'Kovid Goyal'
23- timefmt = ''
2423 no_stylesheets = True
2524 language = 'en'
2625 encoding = 'utf-8'
27- remove_attributes = ['style' ]
26+ remove_attributes = ['style' , 'height' , 'width' ]
27+ oldest_article = 2 # days
2828 INDEX = 'https://slate.com'
29- compress_news_images = True
29+ resolve_internal_links = True
30+ remove_empty_feeds = True
31+ ignore_duplicate_articles = {'url' }
32+
33+ extra_css = '''
34+ .article__rubric { font-size:small; color:#404040; }
35+ .article__byline, time { font-size:small; }
36+ .article__top-image, .image__credit, .image__meta { font-size:small; text-align:center; }
37+ em, blockquote, .alternativeHeadline { color:#202020; }
38+ '''
3039
3140 keep_only_tags = [
32- classes ('article__header article__content' ),
41+ classes ('article__header article__top-image article__content article-hotseats__body ' ),
3342 ]
3443 remove_tags = [
44+ dict (name = ['aside' , 'svg' , 'iframe' ]),
3545 classes ('social-share slate-ad newsletter-signup in-article-recirc' ),
3646 ]
3747
3848 def preprocess_html (self , soup ):
49+ for h2 in soup .findAll ('h2' ):
50+ h2 .name = 'h4'
3951 for img in soup .findAll ('img' , attrs = {'data-srcset' : True }):
40- img ['src' ] = img ['data-srcset' ]. split ()[ 0 ]
52+ img ['src' ] = img ['data-src' ] + '&width=600'
4153 return soup
4254
43- def parse_index (self ):
44- ans = []
45- for sectitle , url in (
46- ('News & Politics' , '/articles/news_and_politics.html' ),
47- ('Technology' , '/articles/technology.html' ),
48- ('Business' , '/articles/business.html' ),
49- ('Arts' , '/articles/arts.html' ),
50- ('Life' , '/articles/life.html' ),
51- ('Health & Science' , '/articles/health_and_science.html' ),
52- ('Sports' , '/articles/sports.html' ),
53- ('Double X' , '/articles/double_x.html' ),
54- ):
55- url = self .INDEX + url
56- self .log ('\n Found section:' , sectitle , url )
57- articles = self .slate_section_articles (self .index_to_soup (url ))
58- if articles :
59- ans .append ((sectitle , articles ))
60- if self .test and len (ans ) > 1 :
61- break
62- return ans
55+ feeds = [
56+ ('News & Politics' , 'https://slate.com/feeds/news-and-politics.rss' ),
57+ ('Culture' , 'https://slate.com/feeds/culture.rss' ),
58+ ('Technology' , 'https://slate.com/feeds/technology.rss' ),
59+ ('Business' , 'https://slate.com/feeds/business.rss' ),
60+ ('Human Interest' , 'https://slate.com/feeds/human-interest.rss' ),
61+ ('Others' , 'https://slate.com/feeds/all.rss' )
62+ ]
6363
64- def slate_section_articles (self , soup ):
65- ans = []
66- main = soup .find ('section' , ** classes ('main' ))
67- if main is None :
68- return ans
69- for div in main .findAll (** classes ('section-feed__item' )):
70- a = div .find ('a' )
71- url = a ['href' ]
72- if url .endswith ('/' ):
73- continue
74- h = a .find (['h2' , 'h3' , 'h4' ])
75- title = self .tag_to_string (h )
76- desc = ''
77- for q in ('byline' , 'dek' ):
78- span = div .find (attrs = {'class' : lambda x : x and ('-' + q ) in x })
79- if span is not None :
80- desc += self .tag_to_string (span ).strip ()
81- self .log ('\t ' + title )
82- self .log ('\t \t ' + url )
83- ans .append ({'title' : title , 'description' : desc .strip (),
84- 'date' : '' , 'url' : url })
85- return ans
64+ def get_article_url (self , article ):
65+ url = BasicNewsRecipe .get_article_url (self , article )
66+ if '/podcasts/' not in url :
67+ return url .split ('?' )[0 ]
0 commit comments