Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

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