Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 2869-2905 (lines=37) @@
2866
        return {
2867
            'short_url': short_url,
2868
            'num': num,
2869
            'img': [i['src'] for i in imgs],
2870
            'month': day.month,
2871
            'year': day.year,
2872
            'day': day.day,
2873
            'title': title,
2874
            'tags': tags,
2875
            'alt': alt,
2876
            'author': author,
2877
        }
2878
2879
2880
class AHamADay(GenericNavigableComic):
2881
    """Class to retrieve class A Ham A Day comics."""
2882
    name = 'ham'
2883
    long_name = 'A Ham A Day'
2884
    url = 'http://www.ahammaday.com'
2885
    get_url_from_link = join_cls_url_to_href
2886
    get_first_comic_link = simulate_first_link
2887
    first_url = 'http://www.ahammaday.com/today/3/6/french'
2888
2889
    @classmethod
2890
    def get_navi_link(cls, last_soup, next_):
2891
        """Get link to next or previous comic."""
2892
        # prev is next / next is prev
2893
        return last_soup.find('li', class_='previous' if next_ else 'next').find('a')
2894
2895
    @classmethod
2896
    def get_comic_info(cls, soup, link):
2897
        """Get information about a particular comics."""
2898
        date_str = soup.find('time', class_='published')['datetime']
2899
        day = string_to_date(date_str, "%Y-%m-%d")
2900
        author = soup.find('span', class_='blog-author').find('a').string
2901
        title = soup.find('meta', property='og:title')['content']
2902
        imgs = soup.find_all('meta', itemprop='image')
2903
        return {
2904
            'img': [i['content'] for i in imgs],
2905
            'title': title,
2906
            'author': author,
2907
            'day': day.day,
2908
            'month': day.month,
@@ 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_):