Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 2999-3035 (lines=37) @@
2996
2997
    @classmethod
2998
    def get_comic_info(cls, soup, link):
2999
        """Get information about a particular comics."""
3000
        title = soup.find('h2', class_='post-title').string
3001
        short_url = soup.find('link', rel='shortlink')['href']
3002
        short_url_re = re.compile('^%s/\\?p=([0-9]*)' % cls.url)
3003
        num = int(short_url_re.match(short_url).groups()[0])
3004
        imgs = soup.find('div', id='comic').find_all('img')
3005
        alt = imgs[0]['title']
3006
        assert all(i['alt'] == i['title'] == alt for i in imgs)
3007
        date_str = soup.find('span', class_='post-date').string
3008
        day = string_to_date(date_str, "%B %d, %Y")
3009
        tags = ' '.join(t['content'] for t in soup.find_all('meta', property='article:tag'))
3010
        author = soup.find('span', class_='post-author').string
3011
        return {
3012
            'short_url': short_url,
3013
            'num': num,
3014
            'img': [i['src'] for i in imgs],
3015
            'month': day.month,
3016
            'year': day.year,
3017
            'day': day.day,
3018
            'title': title,
3019
            'tags': tags,
3020
            'alt': alt,
3021
            'author': author,
3022
        }
3023
3024
3025
class AHammADay(GenericComicNotWorking, GenericNavigableComic):  # Website has changed
3026
    """Class to retrieve class A Hamm A Day comics."""
3027
    name = 'hamm'
3028
    long_name = 'A Hamm A Day'
3029
    url = 'http://www.ahammaday.com'
3030
    get_url_from_link = join_cls_url_to_href
3031
    get_first_comic_link = simulate_first_link
3032
    first_url = 'http://www.ahammaday.com/today/3/6/french'
3033
3034
    @classmethod
3035
    def get_navi_link(cls, last_soup, next_):
3036
        """Get link to next or previous comic."""
3037
        # prev is next / next is prev
3038
        return last_soup.find('li', class_='previous' if next_ else 'next').find('a')
@@ 782-816 (lines=35) @@
779
        }
780
781
782
class Garfield(GenericNavigableComic):
783
    """Class to retrieve Garfield comics."""
784
    # Also on http://www.gocomics.com/garfield
785
    name = 'garfield'
786
    long_name = 'Garfield'
787
    url = 'https://garfield.com'
788
    _categories = ('GARFIELD', )
789
    get_first_comic_link = simulate_first_link
790
    first_url = 'https://garfield.com/comic/1978/06/19'
791
792
    @classmethod
793
    def get_navi_link(cls, last_soup, next_):
794
        """Get link to next or previous comic."""
795
        return last_soup.find('a', class_='comic-arrow-right' if next_ else 'comic-arrow-left')
796
797
    @classmethod
798
    def get_comic_info(cls, soup, link):
799
        """Get information about a particular comics."""
800
        url = cls.get_url_from_link(link)
801
        date_re = re.compile('^%s/comic/([0-9]*)/([0-9]*)/([0-9]*)' % cls.url)
802
        year, month, day = [int(s) for s in date_re.match(url).groups()]
803
        imgs = soup.find('div', class_='comic-display').find_all('img', class_='img-responsive')
804
        return {
805
            'month': month,
806
            'year': year,
807
            'day': day,
808
            'img': [i['src'] for i in imgs],
809
        }
810
811
812
class Dilbert(GenericNavigableComic):
813
    """Class to retrieve Dilbert comics."""
814
    # Also on http://www.gocomics.com/dilbert-classics
815
    name = 'dilbert'
816
    long_name = 'Dilbert'
817
    url = 'http://dilbert.com'
818
    get_url_from_link = join_cls_url_to_href
819
    get_first_comic_link = simulate_first_link