Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 2999-3035 (lines=37) @@
2996
        }
2997
2998
2999
class LittleLifeLines(GenericNavigableComic):
3000
    """Class to retrieve Little Life Lines comics."""
3001
    # Also on https://little-life-lines.tumblr.com
3002
    name = 'life'
3003
    long_name = 'Little Life Lines'
3004
    url = 'http://www.littlelifelines.com'
3005
    get_url_from_link = join_cls_url_to_href
3006
    get_first_comic_link = simulate_first_link
3007
    first_url = 'http://www.littlelifelines.com/comics/well-done'
3008
3009
    @classmethod
3010
    def get_navi_link(cls, last_soup, next_):
3011
        """Get link to next or previous comic."""
3012
        # prev is next / next is prev
3013
        li = last_soup.find('li', class_='prev' if next_ else 'next')
3014
        return li.find('a') if li else None
3015
3016
    @classmethod
3017
    def get_comic_info(cls, soup, link):
3018
        """Get information about a particular comics."""
3019
        title = soup.find('meta', property='og:title')['content']
3020
        desc = soup.find('meta', property='og:description')['content']
3021
        date_str = soup.find('time', class_='published')['datetime']
3022
        day = string_to_date(date_str, "%Y-%m-%d")
3023
        author = soup.find('a', rel='author').string
3024
        div_content = soup.find('div', class_="body entry-content")
3025
        imgs = div_content.find_all('img')
3026
        imgs = [i for i in imgs if i.get('src') is not None]
3027
        alt = imgs[0]['alt']
3028
        return {
3029
            'title': title,
3030
            'alt': alt,
3031
            'description': desc,
3032
            'author': author,
3033
            'day': day.day,
3034
            'month': day.month,
3035
            'year': day.year,
3036
            'img': [i['src'] for i in imgs],
3037
        }
3038
@@ 782-816 (lines=35) @@
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
819