Code Duplication    Length = 29-32 lines in 3 locations

comics.py 3 locations

@@ 3693-3724 (lines=32) @@
3690
        }
3691
3692
3693
class GenericSquareSpace(GenericNavigableComic):
3694
    """Generic class to retrieve comics using SquareSpace."""
3695
    _categories = ('SQUARESPACE', )
3696
    get_url_from_link = join_cls_url_to_href
3697
    get_first_comic_link = simulate_first_link
3698
3699
    @classmethod
3700
    def get_navi_link(cls, last_soup, next_):
3701
        """Get link to next or previous comic."""
3702
        return last_soup.find('a', id='prevLink' if next_ else 'nextLink')
3703
3704
    @classmethod
3705
    def get_images(cls, soup):
3706
        """Get image URLs for a comic."""
3707
        raise NotImplementedError
3708
3709
    @classmethod
3710
    def get_comic_info(cls, soup, link):
3711
        """Get information about a particular comics."""
3712
        title = soup.find('meta', property='og:title')['content']
3713
        desc = soup.find('meta', property='og:description')['content']
3714
        date_str = soup.find('time', itemprop='datePublished')["datetime"]
3715
        day = string_to_date(date_str, "%Y-%m-%d")
3716
        author = soup.find('a', rel='author').string
3717
        return {
3718
            'title': title,
3719
            'img': cls.get_images(soup),
3720
            'month': day.month,
3721
            'year': day.year,
3722
            'day': day.day,
3723
            'author': author,
3724
            'description': desc,
3725
        }
3726
3727
@@ 3541-3570 (lines=30) @@
3538
        }
3539
3540
3541
class ConsoliaComics(GenericNavigableComic):
3542
    """Class to retrieve Consolia comics."""
3543
    name = 'consolia'
3544
    long_name = 'consolia'
3545
    url = 'https://consolia-comic.com'
3546
    get_url_from_link = join_cls_url_to_href
3547
3548
    @classmethod
3549
    def get_first_comic_link(cls):
3550
        """Get link to first comics."""
3551
        return get_soup_at_url(cls.url).find('a', class_='first')
3552
3553
    @classmethod
3554
    def get_navi_link(cls, last_soup, next_):
3555
        """Get link to next or previous comic."""
3556
        return last_soup.find('a', class_='next' if next_ else 'prev')
3557
3558
    @classmethod
3559
    def get_comic_info(cls, soup, link):
3560
        """Get information about a particular comics."""
3561
        title = soup.find('meta', property='og:title')['content']
3562
        date_str = soup.find('time')["datetime"]
3563
        day = string_to_date(date_str, "%Y-%m-%d")
3564
        imgs = soup.find_all('meta', property='og:image')
3565
        return {
3566
            'title': title,
3567
            'img': [i['content'] for i in imgs],
3568
            'day': day.day,
3569
            'month': day.month,
3570
            'year': day.year,
3571
        }
3572
3573
@@ 3360-3388 (lines=29) @@
3357
        }
3358
3359
3360
class PomComics(GenericNavigableComic):
3361
    """Class to retrieve PomComics."""
3362
    name = 'pom'
3363
    long_name = 'Pom Comics / Piece of Me'
3364
    url = 'http://www.pomcomic.com'
3365
    get_url_from_link = join_cls_url_to_href
3366
3367
    @classmethod
3368
    def get_first_comic_link(cls):
3369
        """Get link to first comics."""
3370
        return get_soup_at_url(cls.url).find('a', class_='btn-first')
3371
3372
    @classmethod
3373
    def get_navi_link(cls, last_soup, next_):
3374
        """Get link to next or previous comic."""
3375
        return last_soup.find('a', class_='btn-next' if next_ else 'btn-prev')
3376
3377
    @classmethod
3378
    def get_comic_info(cls, soup, link):
3379
        """Get information about a particular comics."""
3380
        title = soup.find('h1').string
3381
        desc = soup.find('meta', property='og:description')['content']
3382
        tags = soup.find('meta', attrs={'name': 'keywords'})['content']
3383
        imgs = soup.find('div', class_='comic').find_all('img')
3384
        return {
3385
            'title': title,
3386
            'desc': desc,
3387
            'tags': tags,
3388
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
3389
        }
3390
3391