Code Duplication    Length = 37-39 lines in 2 locations

comics.py 2 locations

@@ 2896-2934 (lines=39) @@
2893
        }
2894
2895
2896
class LittleLifeLines(GenericNavigableComic):
2897
    """Class to retrieve Little Life Lines comics."""
2898
    name = 'life'
2899
    long_name = 'Little Life Lines'
2900
    url = 'http://www.littlelifelines.com'
2901
    get_url_from_link = join_cls_url_to_href
2902
2903
    @classmethod
2904
    def get_first_comic_link(cls):
2905
        """Get link to first comics."""
2906
        return {'href': 'http://www.littlelifelines.com/comics/well-done'}
2907
2908
    @classmethod
2909
    def get_navi_link(cls, last_soup, next_):
2910
        # prev is next / next is prev
2911
        li = last_soup.find('li', class_='prev' if next_ else 'next')
2912
        return li.find('a') if li else None
2913
2914
    @classmethod
2915
    def get_comic_info(cls, soup, link):
2916
        """Get information about a particular comics."""
2917
        title = soup.find('meta', property='og:title')['content']
2918
        desc = soup.find('meta', property='og:description')['content']
2919
        date_str = soup.find('time', class_='published')['datetime']
2920
        day = string_to_date(date_str, "%Y-%m-%d")
2921
        author = soup.find('a', rel='author').string
2922
        div_content = soup.find('div', class_="body entry-content")
2923
        imgs = div_content.find_all('img')
2924
        imgs = [i for i in imgs if i.get('src') is not None]
2925
        alt = imgs[0]['alt']
2926
        return {
2927
            'title': title,
2928
            'alt': alt,
2929
            'description': desc,
2930
            'author': author,
2931
            'day': day.day,
2932
            'month': day.month,
2933
            'year': day.year,
2934
            'img': [i['src'] for i in imgs],
2935
        }
2936
2937
@@ 763-799 (lines=37) @@
760
        }
761
762
763
class Dilbert(GenericNavigableComic):
764
    """Class to retrieve Dilbert comics."""
765
    # Also on http://www.gocomics.com/dilbert-classics
766
    name = 'dilbert'
767
    long_name = 'Dilbert'
768
    url = 'http://dilbert.com'
769
    get_url_from_link = join_cls_url_to_href
770
771
    @classmethod
772
    def get_first_comic_link(cls):
773
        """Get link to first comics."""
774
        return {'href': 'http://dilbert.com/strip/1989-04-16'}
775
776
    @classmethod
777
    def get_navi_link(cls, last_soup, next_):
778
        link = last_soup.find('div', class_='nav-comic nav-right' if next_ else 'nav-comic nav-left')
779
        return link.find('a') if link else None
780
781
    @classmethod
782
    def get_comic_info(cls, soup, link):
783
        """Get information about a particular comics."""
784
        title = soup.find('meta', property='og:title')['content']
785
        imgs = soup.find_all('meta', property='og:image')
786
        desc = soup.find('meta', property='og:description')['content']
787
        date_str = soup.find('meta', property='article:publish_date')['content']
788
        day = string_to_date(date_str, "%B %d, %Y")
789
        author = soup.find('meta', property='article:author')['content']
790
        tags = soup.find('meta', property='article:tag')['content']
791
        return {
792
            'title': title,
793
            'description': desc,
794
            'img': [i['content'] for i in imgs],
795
            'author': author,
796
            'tags': tags,
797
            'day': day.day,
798
            'month': day.month,
799
            'year': day.year
800
        }
801
802