Code Duplication    Length = 19-21 lines in 3 locations

comics.py 3 locations

@@ 3105-3125 (lines=21) @@
3102
3103
    @classmethod
3104
    def get_comic_info(cls, soup, link):
3105
        """Get information about a particular comics."""
3106
        title = soup.find('meta', property='og:title')['content']
3107
        desc = soup.find('meta', property='og:description')['content']
3108
        date_str = soup.find('time', class_='published')['datetime']
3109
        day = string_to_date(date_str, "%Y-%m-%d")
3110
        author = soup.find('a', rel='author').string
3111
        div_content = soup.find('div', class_="body entry-content")
3112
        imgs = div_content.find_all('img')
3113
        imgs = [i for i in imgs if i.get('src') is not None]
3114
        alt = imgs[0]['alt']
3115
        return {
3116
            'title': title,
3117
            'alt': alt,
3118
            'description': desc,
3119
            'author': author,
3120
            'day': day.day,
3121
            'month': day.month,
3122
            'year': day.year,
3123
            'img': [i['src'] for i in imgs],
3124
        }
3125
3126
3127
class GenericWordPressInkblot(GenericNavigableComic):
3128
    """Generic class to retrieve comics using WordPress with Inkblot."""
@@ 828-846 (lines=19) @@
825
        link = last_soup.find('div', class_='nav-comic nav-right' if next_ else 'nav-comic nav-left')
826
        return link.find('a') if link else None
827
828
    @classmethod
829
    def get_comic_info(cls, soup, link):
830
        """Get information about a particular comics."""
831
        title = soup.find('meta', property='og:title')['content']
832
        imgs = soup.find_all('meta', property='og:image')
833
        desc = soup.find('meta', property='og:description')['content']
834
        date_str = soup.find('meta', property='article:publish_date')['content']
835
        day = string_to_date(date_str, "%B %d, %Y")
836
        author = soup.find('meta', property='article:author')['content']
837
        tags = soup.find('meta', property='article:tag')['content']
838
        return {
839
            'title': title,
840
            'description': desc,
841
            'img': [i['content'] for i in imgs],
842
            'author': author,
843
            'tags': tags,
844
            'day': day.day,
845
            'month': day.month,
846
            'year': day.year
847
        }
848
849
@@ 2962-2982 (lines=21) @@
2959
2960
    @classmethod
2961
    def get_comic_info(cls, soup, link):
2962
        """Get information about a particular comics."""
2963
        title = soup.find('h2', class_='post-title').string
2964
        short_url = soup.find('link', rel='shortlink')['href']
2965
        short_url_re = re.compile('^%s/\\?p=([0-9]*)' % cls.url)
2966
        num = int(short_url_re.match(short_url).groups()[0])
2967
        imgs = soup.find('div', id='comic').find_all('img')
2968
        alt = imgs[0]['title']
2969
        assert all(i['alt'] == i['title'] == alt for i in imgs)
2970
        date_str = soup.find('span', class_='post-date').string
2971
        day = string_to_date(date_str, "%d/%m/%Y")
2972
        return {
2973
            'short_url': short_url,
2974
            'num': num,
2975
            'img': [i['src'] for i in imgs],
2976
            'month': day.month,
2977
            'year': day.year,
2978
            'day': day.day,
2979
            'alt': alt,
2980
            'title': title,
2981
        }
2982
2983
2984
class MoonBeard(GenericNavigableComic):
2985
    """Class to retrieve MoonBeard comics."""