Code Duplication    Length = 20-21 lines in 3 locations

comics.py 3 locations

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