From 8cafad010712dc4a33cdeef649dd97275d8ac59b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 6 Mar 2018 04:58:44 +0530 Subject: [PATCH] PEP8 and make class selectors less brittle --- recipes/granta.recipe | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/recipes/granta.recipe b/recipes/granta.recipe index b6539825e8..814009429e 100644 --- a/recipes/granta.recipe +++ b/recipes/granta.recipe @@ -15,6 +15,8 @@ force_issue_download = None ################################################################## # Adapted from https://gist.github.com/FlyingTopHat/7cfdd5434ec704916174 + + def plus_with_unknown_component(first_comp, second_comp, result): if result is None: return first_comp + second_comp @@ -45,11 +47,12 @@ def solve_captcha(captcha): numeric_problem = numeric_problem + str(text2num(part)) # Parse into parts - pattern = re.compile(u'(?P[0-9]+)?' - + u'\s*(?P[+×−])\s*' - + u'(?P[0-9]+)' - + u'\s*(=)\s*' - + u'(?P[0-9]+)?', re.UNICODE) + pattern = re.compile( + u'(?P[0-9]+)?' + u'\s*(?P[+×−])\s*' + u'(?P[0-9]+)' + u'\s*(=)\s*' + u'(?P[0-9]+)?', re.UNICODE) calculationParts = re.search(pattern, numeric_problem) if calculationParts is None: @@ -212,9 +215,8 @@ class Granta(BasicNewsRecipe): articleHeader = soup.find( 'div', attrs={'class': 'article-feature-image-container'}) if articleHeader is None: - # This feels brittle, but bs3 demands a full match articleHeader = soup.find( - 'div', attrs={'class': 'col-xs-12 col-sm-12 col-md-12 article-header'}) + 'div', attrs={'class': lambda x: x and 'article-header' in x.split()}) if articleHeader is not None: image = articleHeader.find( 'div', attrs={'class': 'article-feature-image'}) @@ -238,7 +240,7 @@ class Granta(BasicNewsRecipe): # Get latest issue issueInfo = soup.find( - 'div', attrs={'class': 'dnd_container dnd_container__heading'}) + 'div', attrs={'class': lambda x: x and 'dnd_container__heading' in x.split()}) issueAnchor = issueInfo.find('a') issueTitle = issueAnchor.contents[0]