Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

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