Code Duplication    Length = 29-32 lines in 3 locations

comics.py 3 locations

@@ 3745-3776 (lines=32) @@
3742
        }
3743
3744
3745
class GenericSquareSpace(GenericNavigableComic):
3746
    """Generic class to retrieve comics using SquareSpace."""
3747
    _categories = ('SQUARESPACE', )
3748
    get_url_from_link = join_cls_url_to_href
3749
    get_first_comic_link = simulate_first_link
3750
3751
    @classmethod
3752
    def get_navi_link(cls, last_soup, next_):
3753
        """Get link to next or previous comic."""
3754
        return last_soup.find('a', id='prevLink' if next_ else 'nextLink')
3755
3756
    @classmethod
3757
    def get_images(cls, soup):
3758
        """Get image URLs for a comic."""
3759
        raise NotImplementedError
3760
3761
    @classmethod
3762
    def get_comic_info(cls, soup, link):
3763
        """Get information about a particular comics."""
3764
        title = soup.find('meta', property='og:title')['content']
3765
        desc = soup.find('meta', property='og:description')['content']
3766
        date_str = soup.find('time', itemprop='datePublished')["datetime"]
3767
        day = string_to_date(date_str, "%Y-%m-%d")
3768
        author = soup.find('a', rel='author').string
3769
        return {
3770
            'title': title,
3771
            'img': cls.get_images(soup),
3772
            'month': day.month,
3773
            'year': day.year,
3774
            'day': day.day,
3775
            'author': author,
3776
            'description': desc,
3777
        }
3778
3779
@@ 3593-3622 (lines=30) @@
3590
        }
3591
3592
3593
class ConsoliaComics(GenericNavigableComic):
3594
    """Class to retrieve Consolia comics."""
3595
    name = 'consolia'
3596
    long_name = 'consolia'
3597
    url = 'https://consolia-comic.com'
3598
    get_url_from_link = join_cls_url_to_href
3599
3600
    @classmethod
3601
    def get_first_comic_link(cls):
3602
        """Get link to first comics."""
3603
        return get_soup_at_url(cls.url).find('a', class_='first')
3604
3605
    @classmethod
3606
    def get_navi_link(cls, last_soup, next_):
3607
        """Get link to next or previous comic."""
3608
        return last_soup.find('a', class_='next' if next_ else 'prev')
3609
3610
    @classmethod
3611
    def get_comic_info(cls, soup, link):
3612
        """Get information about a particular comics."""
3613
        title = soup.find('meta', property='og:title')['content']
3614
        date_str = soup.find('time')["datetime"]
3615
        day = string_to_date(date_str, "%Y-%m-%d")
3616
        imgs = soup.find_all('meta', property='og:image')
3617
        return {
3618
            'title': title,
3619
            'img': [i['content'] for i in imgs],
3620
            'day': day.day,
3621
            'month': day.month,
3622
            'year': day.year,
3623
        }
3624
3625
@@ 3412-3440 (lines=29) @@
3409
        }
3410
3411
3412
class PomComics(GenericNavigableComic):
3413
    """Class to retrieve PomComics."""
3414
    name = 'pom'
3415
    long_name = 'Pom Comics / Piece of Me'
3416
    url = 'http://www.pomcomic.com'
3417
    get_url_from_link = join_cls_url_to_href
3418
3419
    @classmethod
3420
    def get_first_comic_link(cls):
3421
        """Get link to first comics."""
3422
        return get_soup_at_url(cls.url).find('a', class_='btn-first')
3423
3424
    @classmethod
3425
    def get_navi_link(cls, last_soup, next_):
3426
        """Get link to next or previous comic."""
3427
        return last_soup.find('a', class_='btn-next' if next_ else 'btn-prev')
3428
3429
    @classmethod
3430
    def get_comic_info(cls, soup, link):
3431
        """Get information about a particular comics."""
3432
        title = soup.find('h1').string
3433
        desc = soup.find('meta', property='og:description')['content']
3434
        tags = soup.find('meta', attrs={'name': 'keywords'})['content']
3435
        imgs = soup.find('div', class_='comic').find_all('img')
3436
        return {
3437
            'title': title,
3438
            'desc': desc,
3439
            'tags': tags,
3440
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
3441
        }
3442
3443