Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 831-865 (lines=35) @@
828
        }
829
830
831
class Dilbert(GenericNavigableComic):
832
    """Class to retrieve Dilbert comics."""
833
    # Also on http://www.gocomics.com/dilbert-classics
834
    name = 'dilbert'
835
    long_name = 'Dilbert'
836
    url = 'http://dilbert.com'
837
    get_url_from_link = join_cls_url_to_href
838
    get_first_comic_link = simulate_first_link
839
    first_url = 'http://dilbert.com/strip/1989-04-16'
840
841
    @classmethod
842
    def get_navi_link(cls, last_soup, next_):
843
        """Get link to next or previous comic."""
844
        link = last_soup.find('div', class_='nav-comic nav-right' if next_ else 'nav-comic nav-left')
845
        return link.find('a') if link else None
846
847
    @classmethod
848
    def get_comic_info(cls, soup, link):
849
        """Get information about a particular comics."""
850
        title = soup.find('meta', property='og:title')['content']
851
        imgs = soup.find_all('meta', property='og:image')
852
        desc = soup.find('meta', property='og:description')['content']
853
        date_str = soup.find('meta', property='article:publish_date')['content']
854
        day = string_to_date(date_str, "%B %d, %Y")
855
        author = soup.find('meta', property='article:author')['content']
856
        tags = soup.find('meta', property='article:tag')['content']
857
        return {
858
            'title': title,
859
            'description': desc,
860
            'img': [i['content'] for i in imgs],
861
            'author': author,
862
            'tags': tags,
863
            'day': day.day,
864
            'month': day.month,
865
            'year': day.year
866
        }
867
868
@@ 3109-3145 (lines=37) @@
3106
    name = 'system'
3107
    long_name = 'System Comic'
3108
    url = 'http://www.systemcomic.com'
3109
    get_navi_link = get_a_rel_next
3110
3111
    @classmethod
3112
    def get_first_comic_link(cls):
3113
        """Get link to first comics."""
3114
        return get_soup_at_url(cls.url).find('li', class_='first').find('a')
3115
3116
    @classmethod
3117
    def get_comic_info(cls, soup, link):
3118
        """Get information about a particular comics."""
3119
        title = soup.find('meta', property='og:title')['content']
3120
        desc = soup.find('meta', property='og:description')['content']
3121
        date_str = soup.find('time')["datetime"]
3122
        day = string_to_date(date_str, "%Y-%m-%d")
3123
        imgs = soup.find('figure').find_all('img')
3124
        return {
3125
            'title': title,
3126
            'description': desc,
3127
            'day': day.day,
3128
            'month': day.month,
3129
            'year': day.year,
3130
            'img': [i['src'] for i in imgs],
3131
        }
3132
3133
3134
class LittleLifeLines(GenericNavigableComic):
3135
    """Class to retrieve Little Life Lines comics."""
3136
    # Also on https://little-life-lines.tumblr.com
3137
    name = 'life'
3138
    long_name = 'Little Life Lines'
3139
    url = 'http://www.littlelifelines.com'
3140
    get_url_from_link = join_cls_url_to_href
3141
    get_first_comic_link = simulate_first_link
3142
    first_url = 'http://www.littlelifelines.com/comics/well-done'
3143
3144
    @classmethod
3145
    def get_navi_link(cls, last_soup, next_):
3146
        """Get link to next or previous comic."""
3147
        # prev is next / next is prev
3148
        li = last_soup.find('li', class_='prev' if next_ else 'next')