Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

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