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
    name = 'life'
2979
    long_name = 'Little Life Lines'
2980
    url = 'http://www.littlelifelines.com'
2981
    get_url_from_link = join_cls_url_to_href
2982
    get_first_comic_link = simulate_first_link
2983
    first_url = 'http://www.littlelifelines.com/comics/well-done'
2984
2985
    @classmethod
2986
    def get_navi_link(cls, last_soup, next_):
2987
        """Get link to next or previous comic."""
2988
        # prev is next / next is prev
2989
        li = last_soup.find('li', class_='prev' if next_ else 'next')
2990
        return li.find('a') if li else None
2991
2992
    @classmethod
2993
    def get_comic_info(cls, soup, link):
2994
        """Get information about a particular comics."""
2995
        title = soup.find('meta', property='og:title')['content']
2996
        desc = soup.find('meta', property='og:description')['content']
2997
        date_str = soup.find('time', class_='published')['datetime']
2998
        day = string_to_date(date_str, "%Y-%m-%d")
2999
        author = soup.find('a', rel='author').string
3000
        div_content = soup.find('div', class_="body entry-content")
3001
        imgs = div_content.find_all('img')
3002
        imgs = [i for i in imgs if i.get('src') is not None]
3003
        alt = imgs[0]['alt']
3004
        return {
3005
            'title': title,
3006
            'alt': alt,
3007
            'description': desc,
3008
            'author': author,
3009
            'day': day.day,
3010
            'month': day.month,
3011
            'year': day.year,
3012
            'img': [i['src'] for i in imgs],
3013
        }
3014
3015
3016
class GenericWordPressInkblot(GenericNavigableComic):
3017
    """Generic class to retrieve comics using WordPress with Inkblot."""
3018
    get_navi_link = get_link_rel_next
3019
3020
    @classmethod