Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 3097-3133 (lines=37) @@
3094
        }
3095
3096
3097
class LittleLifeLines(GenericNavigableComic):
3098
    """Class to retrieve Little Life Lines comics."""
3099
    # Also on https://little-life-lines.tumblr.com
3100
    name = 'life'
3101
    long_name = 'Little Life Lines'
3102
    url = 'http://www.littlelifelines.com'
3103
    get_url_from_link = join_cls_url_to_href
3104
    get_first_comic_link = simulate_first_link
3105
    first_url = 'http://www.littlelifelines.com/comics/well-done'
3106
3107
    @classmethod
3108
    def get_navi_link(cls, last_soup, next_):
3109
        """Get link to next or previous comic."""
3110
        # prev is next / next is prev
3111
        li = last_soup.find('li', class_='prev' if next_ else 'next')
3112
        return li.find('a') if li else None
3113
3114
    @classmethod
3115
    def get_comic_info(cls, soup, link):
3116
        """Get information about a particular comics."""
3117
        title = soup.find('meta', property='og:title')['content']
3118
        desc = soup.find('meta', property='og:description')['content']
3119
        date_str = soup.find('time', class_='published')['datetime']
3120
        day = string_to_date(date_str, "%Y-%m-%d")
3121
        author = soup.find('a', rel='author').string
3122
        div_content = soup.find('div', class_="body entry-content")
3123
        imgs = div_content.find_all('img')
3124
        imgs = [i for i in imgs if i.get('src') is not None]
3125
        alt = imgs[0]['alt']
3126
        return {
3127
            'title': title,
3128
            'alt': alt,
3129
            'description': desc,
3130
            'author': author,
3131
            'day': day.day,
3132
            'month': day.month,
3133
            'year': day.year,
3134
            'img': [i['src'] for i in imgs],
3135
        }
3136
@@ 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