Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 2869-2905 (lines=37) @@
2866
            'day': day.day,
2867
            'title': title,
2868
            'tags': tags,
2869
            'alt': alt,
2870
            'author': author,
2871
        }
2872
2873
2874
class AHamADay(GenericNavigableComic):
2875
    """Class to retrieve class A Ham A Day comics."""
2876
    name = 'ham'
2877
    long_name = 'A Ham A Day'
2878
    url = 'http://www.ahammaday.com'
2879
    get_url_from_link = join_cls_url_to_href
2880
    get_first_comic_link = simulate_first_link
2881
    first_url = 'http://www.ahammaday.com/today/3/6/french'
2882
2883
    @classmethod
2884
    def get_navi_link(cls, last_soup, next_):
2885
        """Get link to next or previous comic."""
2886
        # prev is next / next is prev
2887
        return last_soup.find('li', class_='previous' if next_ else 'next').find('a')
2888
2889
    @classmethod
2890
    def get_comic_info(cls, soup, link):
2891
        """Get information about a particular comics."""
2892
        date_str = soup.find('time', class_='published')['datetime']
2893
        day = string_to_date(date_str, "%Y-%m-%d")
2894
        author = soup.find('span', class_='blog-author').find('a').string
2895
        title = soup.find('meta', property='og:title')['content']
2896
        imgs = soup.find_all('meta', itemprop='image')
2897
        return {
2898
            'img': [i['content'] for i in imgs],
2899
            'title': title,
2900
            'author': author,
2901
            'day': day.day,
2902
            'month': day.month,
2903
            'year': day.year,
2904
        }
2905
2906
2907
class LittleLifeLines(GenericNavigableComic):
2908
    """Class to retrieve Little Life Lines comics."""
@@ 758-792 (lines=35) @@
755
    """Class to retrieve Garfield comics."""
756
    # Also on http://www.gocomics.com/garfield
757
    name = 'garfield'
758
    long_name = 'Garfield'
759
    url = 'https://garfield.com'
760
    _categories = ('GARFIELD', )
761
    get_first_comic_link = simulate_first_link
762
    first_url = 'https://garfield.com/comic/1978/06/19'
763
764
    @classmethod
765
    def get_navi_link(cls, last_soup, next_):
766
        """Get link to next or previous comic."""
767
        return last_soup.find('a', class_='comic-arrow-right' if next_ else 'comic-arrow-left')
768
769
    @classmethod
770
    def get_comic_info(cls, soup, link):
771
        """Get information about a particular comics."""
772
        url = cls.get_url_from_link(link)
773
        date_re = re.compile('^%s/comic/([0-9]*)/([0-9]*)/([0-9]*)' % cls.url)
774
        year, month, day = [int(s) for s in date_re.match(url).groups()]
775
        imgs = soup.find('div', class_='comic-display').find_all('img', class_='img-responsive')
776
        return {
777
            'month': month,
778
            'year': year,
779
            'day': day,
780
            'img': [i['src'] for i in imgs],
781
        }
782
783
784
class Dilbert(GenericNavigableComic):
785
    """Class to retrieve Dilbert comics."""
786
    # Also on http://www.gocomics.com/dilbert-classics
787
    name = 'dilbert'
788
    long_name = 'Dilbert'
789
    url = 'http://dilbert.com'
790
    get_url_from_link = join_cls_url_to_href
791
    get_first_comic_link = simulate_first_link
792
    first_url = 'http://dilbert.com/strip/1989-04-16'
793
794
    @classmethod
795
    def get_navi_link(cls, last_soup, next_):