Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

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