Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

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