Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 2869-2905 (lines=37) @@
2866
    get_first_comic_link = get_a_navi_navifirst
2867
    get_navi_link = get_a_navi_navinext
2868
2869
    @classmethod
2870
    def get_comic_info(cls, soup, link):
2871
        """Get information about a particular comics."""
2872
        title = soup.find('h2', class_='post-title').string
2873
        short_url = soup.find('link', rel='shortlink')['href']
2874
        short_url_re = re.compile('^%s/\\?p=([0-9]*)' % cls.url)
2875
        num = int(short_url_re.match(short_url).groups()[0])
2876
        imgs = soup.find('div', id='comic').find_all('img')
2877
        alt = imgs[0]['title']
2878
        assert all(i['alt'] == i['title'] == alt for i in imgs)
2879
        date_str = soup.find('span', class_='post-date').string
2880
        day = string_to_date(date_str, "%B %d, %Y")
2881
        tags = ' '.join(t['content'] for t in soup.find_all('meta', property='article:tag'))
2882
        author = soup.find('span', class_='post-author').string
2883
        return {
2884
            'short_url': short_url,
2885
            'num': num,
2886
            'img': [i['src'] for i in imgs],
2887
            'month': day.month,
2888
            'year': day.year,
2889
            'day': day.day,
2890
            'title': title,
2891
            'tags': tags,
2892
            'alt': alt,
2893
            'author': author,
2894
        }
2895
2896
2897
class AHamADay(GenericNavigableComic):
2898
    """Class to retrieve class A Ham A Day comics."""
2899
    name = 'ham'
2900
    long_name = 'A Ham A Day'
2901
    url = 'http://www.ahammaday.com'
2902
    get_url_from_link = join_cls_url_to_href
2903
    get_first_comic_link = simulate_first_link
2904
    first_url = 'http://www.ahammaday.com/today/3/6/french'
2905
2906
    @classmethod
2907
    def get_navi_link(cls, last_soup, next_):
2908
        """Get link to next or previous comic."""
@@ 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_):