Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 2869-2905 (lines=37) @@
2866
            'year': day.year,
2867
        }
2868
2869
2870
class LittleLifeLines(GenericNavigableComic):
2871
    """Class to retrieve Little Life Lines comics."""
2872
    name = 'life'
2873
    long_name = 'Little Life Lines'
2874
    url = 'http://www.littlelifelines.com'
2875
    get_url_from_link = join_cls_url_to_href
2876
    get_first_comic_link = simulate_first_link
2877
    first_url = 'http://www.littlelifelines.com/comics/well-done'
2878
2879
    @classmethod
2880
    def get_navi_link(cls, last_soup, next_):
2881
        """Get link to next or previous comic."""
2882
        # prev is next / next is prev
2883
        li = last_soup.find('li', class_='prev' if next_ else 'next')
2884
        return li.find('a') if li else None
2885
2886
    @classmethod
2887
    def get_comic_info(cls, soup, link):
2888
        """Get information about a particular comics."""
2889
        title = soup.find('meta', property='og:title')['content']
2890
        desc = soup.find('meta', property='og:description')['content']
2891
        date_str = soup.find('time', class_='published')['datetime']
2892
        day = string_to_date(date_str, "%Y-%m-%d")
2893
        author = soup.find('a', rel='author').string
2894
        div_content = soup.find('div', class_="body entry-content")
2895
        imgs = div_content.find_all('img')
2896
        imgs = [i for i in imgs if i.get('src') is not None]
2897
        alt = imgs[0]['alt']
2898
        return {
2899
            'title': title,
2900
            'alt': alt,
2901
            'description': desc,
2902
            'author': author,
2903
            'day': day.day,
2904
            'month': day.month,
2905
            'year': day.year,
2906
            'img': [i['src'] for i in imgs],
2907
        }
2908
@@ 758-792 (lines=35) @@
755
            'img': [i['src'] for i in imgs],
756
        }
757
758
759
class Dilbert(GenericNavigableComic):
760
    """Class to retrieve Dilbert comics."""
761
    # Also on http://www.gocomics.com/dilbert-classics
762
    name = 'dilbert'
763
    long_name = 'Dilbert'
764
    url = 'http://dilbert.com'
765
    get_url_from_link = join_cls_url_to_href
766
    get_first_comic_link = simulate_first_link
767
    first_url = 'http://dilbert.com/strip/1989-04-16'
768
769
    @classmethod
770
    def get_navi_link(cls, last_soup, next_):
771
        """Get link to next or previous comic."""
772
        link = last_soup.find('div', class_='nav-comic nav-right' if next_ else 'nav-comic nav-left')
773
        return link.find('a') if link else None
774
775
    @classmethod
776
    def get_comic_info(cls, soup, link):
777
        """Get information about a particular comics."""
778
        title = soup.find('meta', property='og:title')['content']
779
        imgs = soup.find_all('meta', property='og:image')
780
        desc = soup.find('meta', property='og:description')['content']
781
        date_str = soup.find('meta', property='article:publish_date')['content']
782
        day = string_to_date(date_str, "%B %d, %Y")
783
        author = soup.find('meta', property='article:author')['content']
784
        tags = soup.find('meta', property='article:tag')['content']
785
        return {
786
            'title': title,
787
            'description': desc,
788
            'img': [i['content'] for i in imgs],
789
            'author': author,
790
            'tags': tags,
791
            'day': day.day,
792
            'month': day.month,
793
            'year': day.year
794
        }
795