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