Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

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