Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 3161-3197 (lines=37) @@
3158
            'img': [i['src'] for i in imgs],
3159
        }
3160
3161
3162
class LittleLifeLines(GenericNavigableComic):
3163
    """Class to retrieve Little Life Lines comics."""
3164
    # Also on https://little-life-lines.tumblr.com
3165
    name = 'life'
3166
    long_name = 'Little Life Lines'
3167
    url = 'http://www.littlelifelines.com'
3168
    get_url_from_link = join_cls_url_to_href
3169
    get_first_comic_link = simulate_first_link
3170
    first_url = 'http://www.littlelifelines.com/comics/well-done'
3171
3172
    @classmethod
3173
    def get_navi_link(cls, last_soup, next_):
3174
        """Get link to next or previous comic."""
3175
        # prev is next / next is prev
3176
        li = last_soup.find('li', class_='prev' if next_ else 'next')
3177
        return li.find('a') if li else None
3178
3179
    @classmethod
3180
    def get_comic_info(cls, soup, link):
3181
        """Get information about a particular comics."""
3182
        title = soup.find('meta', property='og:title')['content']
3183
        desc = soup.find('meta', property='og:description')['content']
3184
        date_str = soup.find('time', class_='published')['datetime']
3185
        day = string_to_date(date_str, "%Y-%m-%d")
3186
        author = soup.find('a', rel='author').string
3187
        div_content = soup.find('div', class_="body entry-content")
3188
        imgs = div_content.find_all('img')
3189
        imgs = [i for i in imgs if i.get('src') is not None]
3190
        alt = imgs[0]['alt']
3191
        return {
3192
            'title': title,
3193
            'alt': alt,
3194
            'description': desc,
3195
            'author': author,
3196
            'day': day.day,
3197
            'month': day.month,
3198
            'year': day.year,
3199
            'img': [i['src'] for i in imgs],
3200
        }
@@ 857-891 (lines=35) @@
854
            'img': [i['src'] for i in imgs],
855
        }
856
857
858
class Dilbert(GenericNavigableComic):
859
    """Class to retrieve Dilbert comics."""
860
    # Also on http://www.gocomics.com/dilbert-classics
861
    name = 'dilbert'
862
    long_name = 'Dilbert'
863
    url = 'http://dilbert.com'
864
    get_url_from_link = join_cls_url_to_href
865
    get_first_comic_link = simulate_first_link
866
    first_url = 'http://dilbert.com/strip/1989-04-16'
867
868
    @classmethod
869
    def get_navi_link(cls, last_soup, next_):
870
        """Get link to next or previous comic."""
871
        link = last_soup.find('div', class_='nav-comic nav-right' if next_ else 'nav-comic nav-left')
872
        return link.find('a') if link else None
873
874
    @classmethod
875
    def get_comic_info(cls, soup, link):
876
        """Get information about a particular comics."""
877
        title = soup.find('meta', property='og:title')['content']
878
        imgs = soup.find_all('meta', property='og:image')
879
        desc = soup.find('meta', property='og:description')['content']
880
        date_str = soup.find('meta', property='article:publish_date')['content']
881
        day = string_to_date(date_str, "%B %d, %Y")
882
        author = soup.find('meta', property='article:author')['content']
883
        tags = soup.find('meta', property='article:tag')['content']
884
        return {
885
            'title': title,
886
            'description': desc,
887
            'img': [i['content'] for i in imgs],
888
            'author': author,
889
            'tags': tags,
890
            'day': day.day,
891
            'month': day.month,
892
            'year': day.year
893
        }
894