Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

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