Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 2869-2905 (lines=37) @@
2866
2867
class AHamADay(GenericNavigableComic):
2868
    """Class to retrieve class A Ham A Day comics."""
2869
    name = 'ham'
2870
    long_name = 'A Ham A Day'
2871
    url = 'http://www.ahammaday.com'
2872
    get_url_from_link = join_cls_url_to_href
2873
    get_first_comic_link = simulate_first_link
2874
    first_url = 'http://www.ahammaday.com/today/3/6/french'
2875
2876
    @classmethod
2877
    def get_navi_link(cls, last_soup, next_):
2878
        """Get link to next or previous comic."""
2879
        # prev is next / next is prev
2880
        return last_soup.find('li', class_='previous' if next_ else 'next').find('a')
2881
2882
    @classmethod
2883
    def get_comic_info(cls, soup, link):
2884
        """Get information about a particular comics."""
2885
        date_str = soup.find('time', class_='published')['datetime']
2886
        day = string_to_date(date_str, "%Y-%m-%d")
2887
        author = soup.find('span', class_='blog-author').find('a').string
2888
        title = soup.find('meta', property='og:title')['content']
2889
        imgs = soup.find_all('meta', itemprop='image')
2890
        return {
2891
            'img': [i['content'] for i in imgs],
2892
            'title': title,
2893
            'author': author,
2894
            'day': day.day,
2895
            'month': day.month,
2896
            'year': day.year,
2897
        }
2898
2899
2900
class LittleLifeLines(GenericNavigableComic):
2901
    """Class to retrieve Little Life Lines comics."""
2902
    # Also on https://little-life-lines.tumblr.com
2903
    name = 'life'
2904
    long_name = 'Little Life Lines'
2905
    url = 'http://www.littlelifelines.com'
2906
    get_url_from_link = join_cls_url_to_href
2907
    get_first_comic_link = simulate_first_link
2908
    first_url = 'http://www.littlelifelines.com/comics/well-done'
@@ 758-792 (lines=35) @@
755
    @classmethod
756
    def get_comic_info(cls, soup, link):
757
        """Get information about a particular comics."""
758
        url = cls.get_url_from_link(link)
759
        date_re = re.compile('^%s/comic/([0-9]*)/([0-9]*)/([0-9]*)' % cls.url)
760
        year, month, day = [int(s) for s in date_re.match(url).groups()]
761
        imgs = soup.find('div', class_='comic-display').find_all('img', class_='img-responsive')
762
        return {
763
            'month': month,
764
            'year': year,
765
            'day': day,
766
            'img': [i['src'] for i in imgs],
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
        """Get link to next or previous comic."""
783
        link = last_soup.find('div', class_='nav-comic nav-right' if next_ else 'nav-comic nav-left')
784
        return link.find('a') if link else None
785
786
    @classmethod
787
    def get_comic_info(cls, soup, link):
788
        """Get information about a particular comics."""
789
        title = soup.find('meta', property='og:title')['content']
790
        imgs = soup.find_all('meta', property='og:image')
791
        desc = soup.find('meta', property='og:description')['content']
792
        date_str = soup.find('meta', property='article:publish_date')['content']
793
        day = string_to_date(date_str, "%B %d, %Y")
794
        author = soup.find('meta', property='article:author')['content']
795
        tags = soup.find('meta', property='article:tag')['content']