Code Duplication    Length = 29-32 lines in 3 locations

comics.py 3 locations

@@ 3681-3712 (lines=32) @@
3678
        }
3679
3680
3681
class GenericSquareSpace(GenericNavigableComic):
3682
    """Generic class to retrieve comics using SquareSpace."""
3683
    _categories = ('SQUARESPACE', )
3684
    get_url_from_link = join_cls_url_to_href
3685
    get_first_comic_link = simulate_first_link
3686
3687
    @classmethod
3688
    def get_navi_link(cls, last_soup, next_):
3689
        """Get link to next or previous comic."""
3690
        return last_soup.find('a', id='prevLink' if next_ else 'nextLink')
3691
3692
    @classmethod
3693
    def get_images(cls, soup):
3694
        """Get image URLs for a comic."""
3695
        raise NotImplementedError
3696
3697
    @classmethod
3698
    def get_comic_info(cls, soup, link):
3699
        """Get information about a particular comics."""
3700
        title = soup.find('meta', property='og:title')['content']
3701
        desc = soup.find('meta', property='og:description')['content']
3702
        date_str = soup.find('time', itemprop='datePublished')["datetime"]
3703
        day = string_to_date(date_str, "%Y-%m-%d")
3704
        author = soup.find('a', rel='author').string
3705
        return {
3706
            'title': title,
3707
            'img': cls.get_images(soup),
3708
            'month': day.month,
3709
            'year': day.year,
3710
            'day': day.day,
3711
            'author': author,
3712
            'description': desc,
3713
        }
3714
3715
@@ 3529-3558 (lines=30) @@
3526
        }
3527
3528
3529
class ConsoliaComics(GenericNavigableComic):
3530
    """Class to retrieve Consolia comics."""
3531
    name = 'consolia'
3532
    long_name = 'consolia'
3533
    url = 'https://consolia-comic.com'
3534
    get_url_from_link = join_cls_url_to_href
3535
3536
    @classmethod
3537
    def get_first_comic_link(cls):
3538
        """Get link to first comics."""
3539
        return get_soup_at_url(cls.url).find('a', class_='first')
3540
3541
    @classmethod
3542
    def get_navi_link(cls, last_soup, next_):
3543
        """Get link to next or previous comic."""
3544
        return last_soup.find('a', class_='next' if next_ else 'prev')
3545
3546
    @classmethod
3547
    def get_comic_info(cls, soup, link):
3548
        """Get information about a particular comics."""
3549
        title = soup.find('meta', property='og:title')['content']
3550
        date_str = soup.find('time')["datetime"]
3551
        day = string_to_date(date_str, "%Y-%m-%d")
3552
        imgs = soup.find_all('meta', property='og:image')
3553
        return {
3554
            'title': title,
3555
            'img': [i['content'] for i in imgs],
3556
            'day': day.day,
3557
            'month': day.month,
3558
            'year': day.year,
3559
        }
3560
3561
@@ 3348-3376 (lines=29) @@
3345
        }
3346
3347
3348
class PomComics(GenericNavigableComic):
3349
    """Class to retrieve PomComics."""
3350
    name = 'pom'
3351
    long_name = 'Pom Comics / Piece of Me'
3352
    url = 'http://www.pomcomic.com'
3353
    get_url_from_link = join_cls_url_to_href
3354
3355
    @classmethod
3356
    def get_first_comic_link(cls):
3357
        """Get link to first comics."""
3358
        return get_soup_at_url(cls.url).find('a', class_='btn-first')
3359
3360
    @classmethod
3361
    def get_navi_link(cls, last_soup, next_):
3362
        """Get link to next or previous comic."""
3363
        return last_soup.find('a', class_='btn-next' if next_ else 'btn-prev')
3364
3365
    @classmethod
3366
    def get_comic_info(cls, soup, link):
3367
        """Get information about a particular comics."""
3368
        title = soup.find('h1').string
3369
        desc = soup.find('meta', property='og:description')['content']
3370
        tags = soup.find('meta', attrs={'name': 'keywords'})['content']
3371
        imgs = soup.find('div', class_='comic').find_all('img')
3372
        return {
3373
            'title': title,
3374
            'desc': desc,
3375
            'tags': tags,
3376
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
3377
        }
3378
3379