Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 2999-3035 (lines=37) @@
2996
    long_name = 'System Comic'
2997
    url = 'http://www.systemcomic.com'
2998
    get_navi_link = get_a_rel_next
2999
3000
    @classmethod
3001
    def get_first_comic_link(cls):
3002
        """Get link to first comics."""
3003
        return get_soup_at_url(cls.url).find('li', class_='first').find('a')
3004
3005
    @classmethod
3006
    def get_comic_info(cls, soup, link):
3007
        """Get information about a particular comics."""
3008
        title = soup.find('meta', property='og:title')['content']
3009
        desc = soup.find('meta', property='og:description')['content']
3010
        date_str = soup.find('time')["datetime"]
3011
        day = string_to_date(date_str, "%Y-%m-%d")
3012
        imgs = soup.find('figure').find_all('img')
3013
        return {
3014
            'title': title,
3015
            'description': desc,
3016
            'day': day.day,
3017
            'month': day.month,
3018
            'year': day.year,
3019
            'img': [i['src'] for i in imgs],
3020
        }
3021
3022
3023
class LittleLifeLines(GenericNavigableComic):
3024
    """Class to retrieve Little Life Lines comics."""
3025
    # Also on https://little-life-lines.tumblr.com
3026
    name = 'life'
3027
    long_name = 'Little Life Lines'
3028
    url = 'http://www.littlelifelines.com'
3029
    get_url_from_link = join_cls_url_to_href
3030
    get_first_comic_link = simulate_first_link
3031
    first_url = 'http://www.littlelifelines.com/comics/well-done'
3032
3033
    @classmethod
3034
    def get_navi_link(cls, last_soup, next_):
3035
        """Get link to next or previous comic."""
3036
        # prev is next / next is prev
3037
        li = last_soup.find('li', class_='prev' if next_ else 'next')
3038
        return li.find('a') if li else None
@@ 782-816 (lines=35) @@
779
            'title2': title2,
780
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
781
            'num': num,
782
        }
783
784
785
class Garfield(GenericNavigableComic):
786
    """Class to retrieve Garfield comics."""
787
    # Also on http://www.gocomics.com/garfield
788
    name = 'garfield'
789
    long_name = 'Garfield'
790
    url = 'https://garfield.com'
791
    _categories = ('GARFIELD', )
792
    get_first_comic_link = simulate_first_link
793
    first_url = 'https://garfield.com/comic/1978/06/19'
794
795
    @classmethod
796
    def get_navi_link(cls, last_soup, next_):
797
        """Get link to next or previous comic."""
798
        return last_soup.find('a', class_='comic-arrow-right' if next_ else 'comic-arrow-left')
799
800
    @classmethod
801
    def get_comic_info(cls, soup, link):
802
        """Get information about a particular comics."""
803
        url = cls.get_url_from_link(link)
804
        date_re = re.compile('^%s/comic/([0-9]*)/([0-9]*)/([0-9]*)' % cls.url)
805
        year, month, day = [int(s) for s in date_re.match(url).groups()]
806
        imgs = soup.find('div', class_='comic-display').find_all('img', class_='img-responsive')
807
        return {
808
            'month': month,
809
            'year': year,
810
            'day': day,
811
            'img': [i['src'] for i in imgs],
812
        }
813
814
815
class Dilbert(GenericNavigableComic):
816
    """Class to retrieve Dilbert comics."""
817
    # Also on http://www.gocomics.com/dilbert-classics
818
    name = 'dilbert'
819
    long_name = 'Dilbert'