Code Duplication    Length = 20-21 lines in 3 locations

comics.py 3 locations

@@ 2927-2947 (lines=21) @@
2924
        li = last_soup.find('li', class_='prev' if next_ else 'next')
2925
        return li.find('a') if li else None
2926
2927
    @classmethod
2928
    def get_comic_info(cls, soup, link):
2929
        """Get information about a particular comics."""
2930
        title = soup.find('meta', property='og:title')['content']
2931
        desc = soup.find('meta', property='og:description')['content']
2932
        date_str = soup.find('time', class_='published')['datetime']
2933
        day = string_to_date(date_str, "%Y-%m-%d")
2934
        author = soup.find('a', rel='author').string
2935
        div_content = soup.find('div', class_="body entry-content")
2936
        imgs = div_content.find_all('img')
2937
        imgs = [i for i in imgs if i.get('src') is not None]
2938
        alt = imgs[0]['alt']
2939
        return {
2940
            'title': title,
2941
            'alt': alt,
2942
            'description': desc,
2943
            'author': author,
2944
            'day': day.day,
2945
            'month': day.month,
2946
            'year': day.year,
2947
            'img': [i['src'] for i in imgs],
2948
        }
2949
2950
@@ 2815-2835 (lines=21) @@
2812
    get_first_comic_link = get_a_navi_navifirst
2813
    get_navi_link = get_link_rel_next
2814
2815
    @classmethod
2816
    def get_comic_info(cls, soup, link):
2817
        """Get information about a particular comics."""
2818
        title = soup.find('h2', class_='post-title').string
2819
        short_url = soup.find('link', rel='shortlink')['href']
2820
        short_url_re = re.compile('^%s/\\?p=([0-9]*)' % cls.url)
2821
        num = int(short_url_re.match(short_url).groups()[0])
2822
        imgs = soup.find('div', id='comic').find_all('img')
2823
        alt = imgs[0]['title']
2824
        assert all(i['alt'] == i['title'] == alt for i in imgs)
2825
        date_str = soup.find('span', class_='post-date').string
2826
        day = string_to_date(date_str, "%d/%m/%Y")
2827
        return {
2828
            'short_url': short_url,
2829
            'num': num,
2830
            'img': [i['src'] for i in imgs],
2831
            'month': day.month,
2832
            'year': day.year,
2833
            'day': day.day,
2834
            'alt': alt,
2835
            'title': title,
2836
        }
2837
2838
@@ 2332-2351 (lines=20) @@
2329
                return link
2330
        return None
2331
2332
    @classmethod
2333
    def get_comic_info(cls, soup, link):
2334
        """Get information about a particular comics."""
2335
        title = soup.find('meta', attrs={'name': 'description'})["content"]
2336
        description = soup.find('div', itemprop='articleBody').text
2337
        author = soup.find('span', itemprop='author copyrightHolder').string
2338
        imgs = soup.find_all('img', itemprop='image')
2339
        assert all(i['title'] == i['alt'] for i in imgs)
2340
        alt = imgs[0]['alt'] if imgs else ""
2341
        date_str = soup.find('time', itemprop='datePublished')["datetime"]
2342
        day = string_to_date(date_str, "%Y-%m-%d %H:%M:%S")
2343
        return {
2344
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
2345
            'month': day.month,
2346
            'year': day.year,
2347
            'day': day.day,
2348
            'author': author,
2349
            'title': title,
2350
            'alt': alt,
2351
            'description': description,
2352
        }
2353
2354