Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 2999-3035 (lines=37) @@
2996
            'year': day.year,
2997
            'day': day.day,
2998
            'alt': alt,
2999
            'title': title,
3000
        }
3001
3002
3003
class MoonBeard(GenericNavigableComic):
3004
    """Class to retrieve MoonBeard comics."""
3005
    # Also on http://squireseses.tumblr.com
3006
    # Also on http://www.webtoons.com/en/comedy/moon-beard/list?title_no=471
3007
    name = 'moonbeard'
3008
    long_name = 'Moon Beard'
3009
    url = 'http://moonbeard.com'
3010
    _categories = ('MOONBEARD', )
3011
    get_first_comic_link = get_a_navi_navifirst
3012
    get_navi_link = get_a_navi_navinext
3013
3014
    @classmethod
3015
    def get_comic_info(cls, soup, link):
3016
        """Get information about a particular comics."""
3017
        title = soup.find('h2', class_='post-title').string
3018
        short_url = soup.find('link', rel='shortlink')['href']
3019
        short_url_re = re.compile('^%s/\\?p=([0-9]*)' % cls.url)
3020
        num = int(short_url_re.match(short_url).groups()[0])
3021
        imgs = soup.find('div', id='comic').find_all('img')
3022
        alt = imgs[0]['title']
3023
        assert all(i['alt'] == i['title'] == alt for i in imgs)
3024
        date_str = soup.find('span', class_='post-date').string
3025
        day = string_to_date(date_str, "%B %d, %Y")
3026
        tags = ' '.join(t['content'] for t in soup.find_all('meta', property='article:tag'))
3027
        author = soup.find('span', class_='post-author').string
3028
        return {
3029
            'short_url': short_url,
3030
            'num': num,
3031
            'img': [i['src'] for i in imgs],
3032
            'month': day.month,
3033
            'year': day.year,
3034
            'day': day.day,
3035
            'title': title,
3036
            'tags': tags,
3037
            'alt': alt,
3038
            'author': author,
@@ 782-816 (lines=35) @@
779
    get_navi_link = get_link_rel_next
780
    get_url_from_link = join_cls_url_to_href
781
782
    @classmethod
783
    def get_comic_info(cls, soup, link):
784
        """Get information about a particular comics."""
785
        short_url_re = re.compile('^%s/\\?p=([0-9]*)' % cls.url)
786
        short_url = cls.get_url_from_link(soup.find('link', rel='shortlink'))
787
        num = int(short_url_re.match(short_url).groups()[0])
788
        imgs = soup.find('div', id='comic').find_all('img')
789
        assert len(imgs) == 1, imgs
790
        title = imgs[0]['alt']
791
        title2 = imgs[0]['title']
792
        return {
793
            'short_url': short_url,
794
            'title': title,
795
            'title2': title2,
796
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
797
            'num': num,
798
        }
799
800
801
class Garfield(GenericNavigableComic):
802
    """Class to retrieve Garfield comics."""
803
    # Also on http://www.gocomics.com/garfield
804
    name = 'garfield'
805
    long_name = 'Garfield'
806
    url = 'https://garfield.com'
807
    _categories = ('GARFIELD', )
808
    get_first_comic_link = simulate_first_link
809
    first_url = 'https://garfield.com/comic/1978/06/19'
810
811
    @classmethod
812
    def get_navi_link(cls, last_soup, next_):
813
        """Get link to next or previous comic."""
814
        return last_soup.find('a', class_='comic-arrow-right' if next_ else 'comic-arrow-left')
815
816
    @classmethod
817
    def get_comic_info(cls, soup, link):
818
        """Get information about a particular comics."""
819
        url = cls.get_url_from_link(link)