Code Duplication    Length = 35-37 lines in 2 locations

comics.py 2 locations

@@ 2999-3035 (lines=37) @@
2996
            'short_url': short_url,
2997
            'num': num,
2998
            'img': [i['src'] for i in imgs],
2999
            'month': day.month,
3000
            'year': day.year,
3001
            'day': day.day,
3002
            'title': title,
3003
            'tags': tags,
3004
            'alt': alt,
3005
            'author': author,
3006
        }
3007
3008
3009
class SystemComic(GenericNavigableComic):
3010
    """Class to retrieve System Comic."""
3011
    name = 'system'
3012
    long_name = 'System Comic'
3013
    url = 'http://www.systemcomic.com'
3014
    get_navi_link = get_a_rel_next
3015
3016
    @classmethod
3017
    def get_first_comic_link(cls):
3018
        """Get link to first comics."""
3019
        return get_soup_at_url(cls.url).find('li', class_='first').find('a')
3020
3021
    @classmethod
3022
    def get_comic_info(cls, soup, link):
3023
        """Get information about a particular comics."""
3024
        title = soup.find('meta', property='og:title')['content']
3025
        desc = soup.find('meta', property='og:description')['content']
3026
        date_str = soup.find('time')["datetime"]
3027
        day = string_to_date(date_str, "%Y-%m-%d")
3028
        imgs = soup.find('figure').find_all('img')
3029
        return {
3030
            'title': title,
3031
            'description': desc,
3032
            'day': day.day,
3033
            'month': day.month,
3034
            'year': day.year,
3035
            'img': [i['src'] for i in imgs],
3036
        }
3037
3038
@@ 782-816 (lines=35) @@
779
    get_navi_link = get_link_rel_next
780
    get_url_from_link = join_cls_url_to_href
781
782
    @classmethod
783
    def get_comic_info(cls, soup, link):
784
        """Get information about a particular comics."""
785
        short_url_re = re.compile('^%s/\\?p=([0-9]*)' % cls.url)
786
        short_url = cls.get_url_from_link(soup.find('link', rel='shortlink'))
787
        num = int(short_url_re.match(short_url).groups()[0])
788
        imgs = soup.find('div', id='comic').find_all('img')
789
        assert len(imgs) == 1, imgs
790
        title = imgs[0]['alt']
791
        title2 = imgs[0]['title']
792
        return {
793
            'short_url': short_url,
794
            'title': title,
795
            'title2': title2,
796
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
797
            'num': num,
798
        }
799
800
801
class Garfield(GenericNavigableComic):
802
    """Class to retrieve Garfield comics."""
803
    # Also on http://www.gocomics.com/garfield
804
    name = 'garfield'
805
    long_name = 'Garfield'
806
    url = 'https://garfield.com'
807
    _categories = ('GARFIELD', )
808
    get_first_comic_link = simulate_first_link
809
    first_url = 'https://garfield.com/comic/1978/06/19'
810
811
    @classmethod
812
    def get_navi_link(cls, last_soup, next_):
813
        """Get link to next or previous comic."""
814
        return last_soup.find('a', class_='comic-arrow-right' if next_ else 'comic-arrow-left')
815
816
    @classmethod
817
    def get_comic_info(cls, soup, link):
818
        """Get information about a particular comics."""
819
        url = cls.get_url_from_link(link)