Code Duplication    Length = 26-27 lines in 2 locations

comics.py 2 locations

@@ 543-569 (lines=27) @@
540
        return {
541
            'title': title,
542
            'day': day,
543
            'month': month,
544
            'year': year,
545
            'img': [i['src'] for i in imgs],
546
        }
547
548
549
class ZenPencils(GenericNavigableComic):
550
    """Class to retrieve ZenPencils comics."""
551
    # Also on http://zenpencils.tumblr.com
552
    # Also on http://www.gocomics.com/zen-pencils
553
    name = 'zenpencils'
554
    long_name = 'Zen Pencils'
555
    url = 'http://zenpencils.com'
556
    get_navi_link = get_link_rel_next
557
    get_first_comic_link = simulate_first_link
558
    first_url = "http://zenpencils.com/comic/1-ralph-waldo-emerson-make-them-cry/"
559
560
    @classmethod
561
    def get_comic_info(cls, soup, link):
562
        """Get information about a particular comics."""
563
        imgs = soup.find('div', id='comic').find_all('img')
564
        post = soup.find('div', class_='post-content')
565
        author = post.find("span", class_="post-author").find("a").string
566
        title = post.find('h2', class_='post-title').string
567
        date_str = post.find('span', class_='post-date').string
568
        day = string_to_date(date_str, "%B %d, %Y")
569
        assert imgs
570
        assert all(i['alt'] == i['title'] for i in imgs)
571
        assert all(i['alt'] in (title, "") for i in imgs)
572
        desc = soup.find('meta', property='og:description')['content']
@@ 752-777 (lines=26) @@
749
        return {
750
            'month': month,
751
            'year': year,
752
            'day': day,
753
            'img': [i['src'] for i in imgs],
754
        }
755
756
757
class Dilbert(GenericNavigableComic):
758
    """Class to retrieve Dilbert comics."""
759
    # Also on http://www.gocomics.com/dilbert-classics
760
    name = 'dilbert'
761
    long_name = 'Dilbert'
762
    url = 'http://dilbert.com'
763
    get_url_from_link = join_cls_url_to_href
764
    get_first_comic_link = simulate_first_link
765
    first_url = 'http://dilbert.com/strip/1989-04-16'
766
767
    @classmethod
768
    def get_navi_link(cls, last_soup, next_):
769
        """Get link to next or previous comic."""
770
        link = last_soup.find('div', class_='nav-comic nav-right' if next_ else 'nav-comic nav-left')
771
        return link.find('a') if link else None
772
773
    @classmethod
774
    def get_comic_info(cls, soup, link):
775
        """Get information about a particular comics."""
776
        title = soup.find('meta', property='og:title')['content']
777
        imgs = soup.find_all('meta', property='og:image')
778
        desc = soup.find('meta', property='og:description')['content']
779
        date_str = soup.find('meta', property='article:publish_date')['content']
780
        day = string_to_date(date_str, "%B %d, %Y")