Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 2999-3035 (lines=37) @@
2996
class PainTrainComic(GenericNavigableComic):
2997
    """Class to retrieve Pain Train Comics."""
2998
    name = 'paintrain'
2999
    long_name = 'Pain Train Comics'
3000
    url = 'http://paintraincomic.com'
3001
    get_first_comic_link = get_a_navi_navifirst
3002
    get_navi_link = get_link_rel_next
3003
3004
    @classmethod
3005
    def get_comic_info(cls, soup, link):
3006
        """Get information about a particular comics."""
3007
        title = soup.find('h2', class_='post-title').string
3008
        short_url = soup.find('link', rel='shortlink')['href']
3009
        short_url_re = re.compile('^%s/\\?p=([0-9]*)' % cls.url)
3010
        num = int(short_url_re.match(short_url).groups()[0])
3011
        imgs = soup.find('div', id='comic').find_all('img')
3012
        alt = imgs[0]['title']
3013
        assert all(i['alt'] == i['title'] == alt for i in imgs)
3014
        date_str = soup.find('span', class_='post-date').string
3015
        day = string_to_date(date_str, "%d/%m/%Y")
3016
        return {
3017
            'short_url': short_url,
3018
            'num': num,
3019
            'img': [i['src'] for i in imgs],
3020
            'month': day.month,
3021
            'year': day.year,
3022
            'day': day.day,
3023
            'alt': alt,
3024
            'title': title,
3025
        }
3026
3027
3028
class MoonBeard(GenericNavigableComic):
3029
    """Class to retrieve MoonBeard comics."""
3030
    # Also on http://squireseses.tumblr.com
3031
    # Also on http://www.webtoons.com/en/comedy/moon-beard/list?title_no=471
3032
    name = 'moonbeard'
3033
    long_name = 'Moon Beard'
3034
    url = 'http://moonbeard.com'
3035
    _categories = ('MOONBEARD', )
3036
    get_first_comic_link = get_a_navi_navifirst
3037
    get_navi_link = get_a_navi_navinext
3038
@@ 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)