Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

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