Code Duplication    Length = 34-36 lines in 2 locations

comics.py 2 locations

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