Code Duplication    Length = 29-32 lines in 3 locations

comics.py 3 locations

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