Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 2893-2929 (lines=37) @@
2890
        }
2891
2892
2893
class LittleLifeLines(GenericNavigableComic):
2894
    """Class to retrieve Little Life Lines comics."""
2895
    name = 'life'
2896
    long_name = 'Little Life Lines'
2897
    url = 'http://www.littlelifelines.com'
2898
    get_url_from_link = join_cls_url_to_href
2899
    get_first_comic_link = simulate_first_link
2900
    first_url = 'http://www.littlelifelines.com/comics/well-done'
2901
2902
    @classmethod
2903
    def get_navi_link(cls, last_soup, next_):
2904
        """Get link to next or previous comic."""
2905
        # prev is next / next is prev
2906
        li = last_soup.find('li', class_='prev' if next_ else 'next')
2907
        return li.find('a') if li else None
2908
2909
    @classmethod
2910
    def get_comic_info(cls, soup, link):
2911
        """Get information about a particular comics."""
2912
        title = soup.find('meta', property='og:title')['content']
2913
        desc = soup.find('meta', property='og:description')['content']
2914
        date_str = soup.find('time', class_='published')['datetime']
2915
        day = string_to_date(date_str, "%Y-%m-%d")
2916
        author = soup.find('a', rel='author').string
2917
        div_content = soup.find('div', class_="body entry-content")
2918
        imgs = div_content.find_all('img')
2919
        imgs = [i for i in imgs if i.get('src') is not None]
2920
        alt = imgs[0]['alt']
2921
        return {
2922
            'title': title,
2923
            'alt': alt,
2924
            'description': desc,
2925
            'author': author,
2926
            'day': day.day,
2927
            'month': day.month,
2928
            'year': day.year,
2929
            'img': [i['src'] for i in imgs],
2930
        }
2931
2932
@@ 781-815 (lines=35) @@
778
        }
779
780
781
class Dilbert(GenericNavigableComic):
782
    """Class to retrieve Dilbert comics."""
783
    # Also on http://www.gocomics.com/dilbert-classics
784
    name = 'dilbert'
785
    long_name = 'Dilbert'
786
    url = 'http://dilbert.com'
787
    get_url_from_link = join_cls_url_to_href
788
    get_first_comic_link = simulate_first_link
789
    first_url = 'http://dilbert.com/strip/1989-04-16'
790
791
    @classmethod
792
    def get_navi_link(cls, last_soup, next_):
793
        """Get link to next or previous comic."""
794
        link = last_soup.find('div', class_='nav-comic nav-right' if next_ else 'nav-comic nav-left')
795
        return link.find('a') if link else None
796
797
    @classmethod
798
    def get_comic_info(cls, soup, link):
799
        """Get information about a particular comics."""
800
        title = soup.find('meta', property='og:title')['content']
801
        imgs = soup.find_all('meta', property='og:image')
802
        desc = soup.find('meta', property='og:description')['content']
803
        date_str = soup.find('meta', property='article:publish_date')['content']
804
        day = string_to_date(date_str, "%B %d, %Y")
805
        author = soup.find('meta', property='article:author')['content']
806
        tags = soup.find('meta', property='article:tag')['content']
807
        return {
808
            'title': title,
809
            'description': desc,
810
            'img': [i['content'] for i in imgs],
811
            'author': author,
812
            'tags': tags,
813
            'day': day.day,
814
            'month': day.month,
815
            'year': day.year
816
        }
817
818