Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 781-815 (lines=35) @@
778
            'img': [i['src'] for i in imgs],
779
        }
780
781
782
class Dilbert(GenericNavigableComic):
783
    """Class to retrieve Dilbert comics."""
784
    # Also on http://www.gocomics.com/dilbert-classics
785
    name = 'dilbert'
786
    long_name = 'Dilbert'
787
    url = 'http://dilbert.com'
788
    get_url_from_link = join_cls_url_to_href
789
    get_first_comic_link = simulate_first_link
790
    first_url = 'http://dilbert.com/strip/1989-04-16'
791
792
    @classmethod
793
    def get_navi_link(cls, last_soup, next_):
794
        """Get link to next or previous comic."""
795
        link = last_soup.find('div', class_='nav-comic nav-right' if next_ else 'nav-comic nav-left')
796
        return link.find('a') if link else None
797
798
    @classmethod
799
    def get_comic_info(cls, soup, link):
800
        """Get information about a particular comics."""
801
        title = soup.find('meta', property='og:title')['content']
802
        imgs = soup.find_all('meta', property='og:image')
803
        desc = soup.find('meta', property='og:description')['content']
804
        date_str = soup.find('meta', property='article:publish_date')['content']
805
        day = string_to_date(date_str, "%B %d, %Y")
806
        author = soup.find('meta', property='article:author')['content']
807
        tags = soup.find('meta', property='article:tag')['content']
808
        return {
809
            'title': title,
810
            'description': desc,
811
            'img': [i['content'] for i in imgs],
812
            'author': author,
813
            'tags': tags,
814
            'day': day.day,
815
            'month': day.month,
816
            'year': day.year
817
        }
818
@@ 2981-3017 (lines=37) @@
2978
            'year': day.year,
2979
        }
2980
2981
2982
class LittleLifeLines(GenericNavigableComic):
2983
    """Class to retrieve Little Life Lines comics."""
2984
    # Also on https://little-life-lines.tumblr.com
2985
    name = 'life'
2986
    long_name = 'Little Life Lines'
2987
    url = 'http://www.littlelifelines.com'
2988
    get_url_from_link = join_cls_url_to_href
2989
    get_first_comic_link = simulate_first_link
2990
    first_url = 'http://www.littlelifelines.com/comics/well-done'
2991
2992
    @classmethod
2993
    def get_navi_link(cls, last_soup, next_):
2994
        """Get link to next or previous comic."""
2995
        # prev is next / next is prev
2996
        li = last_soup.find('li', class_='prev' if next_ else 'next')
2997
        return li.find('a') if li else None
2998
2999
    @classmethod
3000
    def get_comic_info(cls, soup, link):
3001
        """Get information about a particular comics."""
3002
        title = soup.find('meta', property='og:title')['content']
3003
        desc = soup.find('meta', property='og:description')['content']
3004
        date_str = soup.find('time', class_='published')['datetime']
3005
        day = string_to_date(date_str, "%Y-%m-%d")
3006
        author = soup.find('a', rel='author').string
3007
        div_content = soup.find('div', class_="body entry-content")
3008
        imgs = div_content.find_all('img')
3009
        imgs = [i for i in imgs if i.get('src') is not None]
3010
        alt = imgs[0]['alt']
3011
        return {
3012
            'title': title,
3013
            'alt': alt,
3014
            'description': desc,
3015
            'author': author,
3016
            'day': day.day,
3017
            'month': day.month,
3018
            'year': day.year,
3019
            'img': [i['src'] for i in imgs],
3020
        }