Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

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