mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
pep8
This commit is contained in:
parent
0e36f48c19
commit
6e81aa8442
@ -48,14 +48,14 @@ class Guardian(BasicNewsRecipe):
|
|||||||
# article history link
|
# article history link
|
||||||
dict(name='a', attrs={'class':["rollover history-link"]}),
|
dict(name='a', attrs={'class':["rollover history-link"]}),
|
||||||
# "a version of this article ..." speil
|
# "a version of this article ..." speil
|
||||||
dict(name='div' , attrs = { 'class' : ['section']}),
|
dict(name='div' , attrs={'class' : ['section']}),
|
||||||
# "about this article" js dialog
|
# "about this article" js dialog
|
||||||
dict(name='div', attrs={'class':["share-top",]}),
|
dict(name='div', attrs={'class':["share-top",]}),
|
||||||
# author picture
|
# author picture
|
||||||
dict(name='img', attrs={'class':["contributor-pic-small"]}),
|
dict(name='img', attrs={'class':["contributor-pic-small"]}),
|
||||||
# embedded videos/captions
|
# embedded videos/captions
|
||||||
dict(name='span',attrs={'class' : ['inline embed embed-media']}),
|
dict(name='span',attrs={'class' : ['inline embed embed-media']}),
|
||||||
#dict(name='img'),
|
# dict(name='img'),
|
||||||
]
|
]
|
||||||
use_embedded_content = False
|
use_embedded_content = False
|
||||||
|
|
||||||
@ -72,12 +72,12 @@ class Guardian(BasicNewsRecipe):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
def get_article_url(self, article):
|
def get_article_url(self, article):
|
||||||
url = article.get('guid', None)
|
url = article.get('guid', None)
|
||||||
if '/video/' in url or '/flyer/' in url or '/quiz/' in url or \
|
if '/video/' in url or '/flyer/' in url or '/quiz/' in url or \
|
||||||
'/gallery/' in url or 'ivebeenthere' in url or \
|
'/gallery/' in url or 'ivebeenthere' in url or \
|
||||||
'pickthescore' in url or 'audioslideshow' in url :
|
'pickthescore' in url or 'audioslideshow' in url :
|
||||||
url = None
|
url = None
|
||||||
return url
|
return url
|
||||||
|
|
||||||
def populate_article_metadata(self, article, soup, first):
|
def populate_article_metadata(self, article, soup, first):
|
||||||
if first and hasattr(self, 'add_toc_thumbnail'):
|
if first and hasattr(self, 'add_toc_thumbnail'):
|
||||||
@ -87,39 +87,39 @@ class Guardian(BasicNewsRecipe):
|
|||||||
|
|
||||||
def preprocess_html(self, soup):
|
def preprocess_html(self, soup):
|
||||||
|
|
||||||
# multiple html sections in soup, useful stuff in the first
|
# multiple html sections in soup, useful stuff in the first
|
||||||
html = soup.find('html')
|
html = soup.find('html')
|
||||||
soup2 = BeautifulSoup()
|
soup2 = BeautifulSoup()
|
||||||
soup2.insert(0,html)
|
soup2.insert(0,html)
|
||||||
|
|
||||||
soup = soup2
|
|
||||||
|
|
||||||
for item in soup.findAll(style=True):
|
|
||||||
del item['style']
|
|
||||||
|
|
||||||
for item in soup.findAll(face=True):
|
soup = soup2
|
||||||
del item['face']
|
|
||||||
for tag in soup.findAll(name=['ul','li']):
|
for item in soup.findAll(style=True):
|
||||||
tag.name = 'div'
|
del item['style']
|
||||||
|
|
||||||
# removes number next to rating stars
|
for item in soup.findAll(face=True):
|
||||||
items_to_remove = []
|
del item['face']
|
||||||
rating_container = soup.find('div', attrs = {'class': ['rating-container']})
|
for tag in soup.findAll(name=['ul','li']):
|
||||||
if rating_container:
|
tag.name = 'div'
|
||||||
|
|
||||||
|
# removes number next to rating stars
|
||||||
|
items_to_remove = []
|
||||||
|
rating_container = soup.find('div', attrs={'class': ['rating-container']})
|
||||||
|
if rating_container:
|
||||||
for item in rating_container:
|
for item in rating_container:
|
||||||
if isinstance(item, Tag) and str(item.name) == 'span':
|
if isinstance(item, Tag) and str(item.name) == 'span':
|
||||||
items_to_remove.append(item)
|
items_to_remove.append(item)
|
||||||
|
|
||||||
for item in items_to_remove:
|
for item in items_to_remove:
|
||||||
item.extract()
|
item.extract()
|
||||||
|
|
||||||
return soup
|
return soup
|
||||||
|
|
||||||
def find_sections(self):
|
def find_sections(self):
|
||||||
# soup = self.index_to_soup("http://www.guardian.co.uk/theobserver")
|
# soup = self.index_to_soup("http://www.guardian.co.uk/theobserver")
|
||||||
soup = self.index_to_soup(self.base_url)
|
soup = self.index_to_soup(self.base_url)
|
||||||
# find cover pic
|
# find cover pic
|
||||||
img = soup.find( 'img',attrs ={'alt':self.cover_pic})
|
img = soup.find('img',attrs={'alt':self.cover_pic})
|
||||||
if img is not None:
|
if img is not None:
|
||||||
self.cover_url = img['src']
|
self.cover_url = img['src']
|
||||||
# end find cover pic
|
# end find cover pic
|
||||||
@ -149,7 +149,8 @@ class Guardian(BasicNewsRecipe):
|
|||||||
continue
|
continue
|
||||||
tt = li.find('div', attrs={'class':'trailtext'})
|
tt = li.find('div', attrs={'class':'trailtext'})
|
||||||
if tt is not None:
|
if tt is not None:
|
||||||
for da in tt.findAll('a'): da.extract()
|
for da in tt.findAll('a'):
|
||||||
|
da.extract()
|
||||||
desc = self.tag_to_string(tt).strip()
|
desc = self.tag_to_string(tt).strip()
|
||||||
yield {
|
yield {
|
||||||
'title': title, 'url':url, 'description':desc,
|
'title': title, 'url':url, 'description':desc,
|
||||||
@ -161,4 +162,3 @@ class Guardian(BasicNewsRecipe):
|
|||||||
for title, href in self.find_sections():
|
for title, href in self.find_sections():
|
||||||
feeds.append((title, list(self.find_articles(href))))
|
feeds.append((title, list(self.find_articles(href))))
|
||||||
return feeds
|
return feeds
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user