Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 2869-2905 (lines=37) @@
2866
            'title': title,
2867
            'alt': alt,
2868
            'author': author,
2869
            'img': [i['src'] for i in imgs],
2870
            'month': day.month,
2871
            'year': day.year,
2872
            'day': day.day,
2873
        }
2874
2875
2876
class PainTrainComic(GenericNavigableComic):
2877
    """Class to retrieve Pain Train Comics."""
2878
    name = 'paintrain'
2879
    long_name = 'Pain Train Comics'
2880
    url = 'http://paintraincomic.com'
2881
    get_first_comic_link = get_a_navi_navifirst
2882
    get_navi_link = get_link_rel_next
2883
2884
    @classmethod
2885
    def get_comic_info(cls, soup, link):
2886
        """Get information about a particular comics."""
2887
        title = soup.find('h2', class_='post-title').string
2888
        short_url = soup.find('link', rel='shortlink')['href']
2889
        short_url_re = re.compile('^%s/\\?p=([0-9]*)' % cls.url)
2890
        num = int(short_url_re.match(short_url).groups()[0])
2891
        imgs = soup.find('div', id='comic').find_all('img')
2892
        alt = imgs[0]['title']
2893
        assert all(i['alt'] == i['title'] == alt for i in imgs)
2894
        date_str = soup.find('span', class_='post-date').string
2895
        day = string_to_date(date_str, "%d/%m/%Y")
2896
        return {
2897
            'short_url': short_url,
2898
            'num': num,
2899
            'img': [i['src'] for i in imgs],
2900
            'month': day.month,
2901
            'year': day.year,
2902
            'day': day.day,
2903
            'alt': alt,
2904
            'title': title,
2905
        }
2906
2907
2908
class MoonBeard(GenericNavigableComic):
@@ 758-792 (lines=35) @@
755
    _categories = ('GARFIELD', )
756
    get_first_comic_link = simulate_first_link
757
    first_url = 'https://garfield.com/comic/1978/06/19'
758
759
    @classmethod
760
    def get_navi_link(cls, last_soup, next_):
761
        """Get link to next or previous comic."""
762
        return last_soup.find('a', class_='comic-arrow-right' if next_ else 'comic-arrow-left')
763
764
    @classmethod
765
    def get_comic_info(cls, soup, link):
766
        """Get information about a particular comics."""
767
        url = cls.get_url_from_link(link)
768
        date_re = re.compile('^%s/comic/([0-9]*)/([0-9]*)/([0-9]*)' % cls.url)
769
        year, month, day = [int(s) for s in date_re.match(url).groups()]
770
        imgs = soup.find('div', class_='comic-display').find_all('img', class_='img-responsive')
771
        return {
772
            'month': month,
773
            'year': year,
774
            'day': day,
775
            'img': [i['src'] for i in imgs],
776
        }
777
778
779
class Dilbert(GenericNavigableComic):
780
    """Class to retrieve Dilbert comics."""
781
    # Also on http://www.gocomics.com/dilbert-classics
782
    name = 'dilbert'
783
    long_name = 'Dilbert'
784
    url = 'http://dilbert.com'
785
    get_url_from_link = join_cls_url_to_href
786
    get_first_comic_link = simulate_first_link
787
    first_url = 'http://dilbert.com/strip/1989-04-16'
788
789
    @classmethod
790
    def get_navi_link(cls, last_soup, next_):
791
        """Get link to next or previous comic."""
792
        link = last_soup.find('div', class_='nav-comic nav-right' if next_ else 'nav-comic nav-left')
793
        return link.find('a') if link else None
794
795
    @classmethod