Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

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