Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

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