Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 2869-2905 (lines=37) @@
2866
        }
2867
2868
2869
class AHamADay(GenericNavigableComic):
2870
    """Class to retrieve class A Ham A Day comics."""
2871
    name = 'ham'
2872
    long_name = 'A Ham A Day'
2873
    url = 'http://www.ahammaday.com'
2874
    get_url_from_link = join_cls_url_to_href
2875
    get_first_comic_link = simulate_first_link
2876
    first_url = 'http://www.ahammaday.com/today/3/6/french'
2877
2878
    @classmethod
2879
    def get_navi_link(cls, last_soup, next_):
2880
        """Get link to next or previous comic."""
2881
        # prev is next / next is prev
2882
        return last_soup.find('li', class_='previous' if next_ else 'next').find('a')
2883
2884
    @classmethod
2885
    def get_comic_info(cls, soup, link):
2886
        """Get information about a particular comics."""
2887
        date_str = soup.find('time', class_='published')['datetime']
2888
        day = string_to_date(date_str, "%Y-%m-%d")
2889
        author = soup.find('span', class_='blog-author').find('a').string
2890
        title = soup.find('meta', property='og:title')['content']
2891
        imgs = soup.find_all('meta', itemprop='image')
2892
        return {
2893
            'img': [i['content'] for i in imgs],
2894
            'title': title,
2895
            'author': author,
2896
            'day': day.day,
2897
            'month': day.month,
2898
            'year': day.year,
2899
        }
2900
2901
2902
class LittleLifeLines(GenericNavigableComic):
2903
    """Class to retrieve Little Life Lines comics."""
2904
    # Also on https://little-life-lines.tumblr.com
2905
    name = 'life'
2906
    long_name = 'Little Life Lines'
2907
    url = 'http://www.littlelifelines.com'
2908
    get_url_from_link = join_cls_url_to_href
@@ 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']