Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 2999-3035 (lines=37) @@
2996
    def get_comic_info(cls, soup, link):
2997
        """Get information about a particular comics."""
2998
        title = soup.find('h2', class_='post-title').string
2999
        short_url = soup.find('link', rel='shortlink')['href']
3000
        short_url_re = re.compile('^%s/\\?p=([0-9]*)' % cls.url)
3001
        num = int(short_url_re.match(short_url).groups()[0])
3002
        imgs = soup.find('div', id='comic').find_all('img')
3003
        alt = imgs[0]['title']
3004
        assert all(i['alt'] == i['title'] == alt for i in imgs)
3005
        date_str = soup.find('span', class_='post-date').string
3006
        day = string_to_date(date_str, "%B %d, %Y")
3007
        tags = ' '.join(t['content'] for t in soup.find_all('meta', property='article:tag'))
3008
        author = soup.find('span', class_='post-author').string
3009
        return {
3010
            'short_url': short_url,
3011
            'num': num,
3012
            'img': [i['src'] for i in imgs],
3013
            'month': day.month,
3014
            'year': day.year,
3015
            'day': day.day,
3016
            'title': title,
3017
            'tags': tags,
3018
            'alt': alt,
3019
            'author': author,
3020
        }
3021
3022
3023
class AHammADay(GenericComicNotWorking, GenericNavigableComic):  # Website has changed
3024
    """Class to retrieve class A Hamm A Day comics."""
3025
    name = 'hamm'
3026
    long_name = 'A Hamm A Day'
3027
    url = 'http://www.ahammaday.com'
3028
    get_url_from_link = join_cls_url_to_href
3029
    get_first_comic_link = simulate_first_link
3030
    first_url = 'http://www.ahammaday.com/today/3/6/french'
3031
3032
    @classmethod
3033
    def get_navi_link(cls, last_soup, next_):
3034
        """Get link to next or previous comic."""
3035
        # prev is next / next is prev
3036
        return last_soup.find('li', class_='previous' if next_ else 'next').find('a')
3037
3038
    @classmethod
@@ 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