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 SystemComic(GenericNavigableComic):
3024
    """Class to retrieve System Comic."""
3025
    name = 'system'
3026
    long_name = 'System Comic'
3027
    url = 'http://www.systemcomic.com'
3028
    get_navi_link = get_a_rel_next
3029
3030
    @classmethod
3031
    def get_first_comic_link(cls):
3032
        """Get link to first comics."""
3033
        return get_soup_at_url(cls.url).find('li', class_='first').find('a')
3034
3035
    @classmethod
3036
    def get_comic_info(cls, soup, link):
3037
        """Get information about a particular comics."""
3038
        title = soup.find('meta', property='og:title')['content']
@@ 782-816 (lines=35) @@
779
            'num': num,
780
        }
781
782
783
class Garfield(GenericNavigableComic):
784
    """Class to retrieve Garfield comics."""
785
    # Also on http://www.gocomics.com/garfield
786
    name = 'garfield'
787
    long_name = 'Garfield'
788
    url = 'https://garfield.com'
789
    _categories = ('GARFIELD', )
790
    get_first_comic_link = simulate_first_link
791
    first_url = 'https://garfield.com/comic/1978/06/19'
792
793
    @classmethod
794
    def get_navi_link(cls, last_soup, next_):
795
        """Get link to next or previous comic."""
796
        return last_soup.find('a', class_='comic-arrow-right' if next_ else 'comic-arrow-left')
797
798
    @classmethod
799
    def get_comic_info(cls, soup, link):
800
        """Get information about a particular comics."""
801
        url = cls.get_url_from_link(link)
802
        date_re = re.compile('^%s/comic/([0-9]*)/([0-9]*)/([0-9]*)' % cls.url)
803
        year, month, day = [int(s) for s in date_re.match(url).groups()]
804
        imgs = soup.find('div', class_='comic-display').find_all('img', class_='img-responsive')
805
        return {
806
            'month': month,
807
            'year': year,
808
            'day': day,
809
            'img': [i['src'] for i in imgs],
810
        }
811
812
813
class Dilbert(GenericNavigableComic):
814
    """Class to retrieve Dilbert comics."""
815
    # Also on http://www.gocomics.com/dilbert-classics
816
    name = 'dilbert'
817
    long_name = 'Dilbert'
818
    url = 'http://dilbert.com'
819
    get_url_from_link = join_cls_url_to_href