Code Duplication    Length = 22-27 lines in 3 locations

comics.py 3 locations

@@ 1361-1387 (lines=27) @@
1358
1359
1360
class ButterSafe(GenericListableComic):
1361
    """Class to retrieve Butter Safe comics."""
1362
    name = 'butter'
1363
    long_name = 'ButterSafe'
1364
    url = 'http://buttersafe.com'
1365
    get_url_from_archive_element = get_href
1366
    comic_link_re = re.compile('^%s/([0-9]*)/([0-9]*)/([0-9]*)/.*' % url)
1367
1368
    @classmethod
1369
    def get_archive_elements(cls):
1370
        archive_url = urljoin_wrapper(cls.url, 'archive/')
1371
        return reversed(get_soup_at_url(archive_url).find_all('a', href=cls.comic_link_re))
1372
1373
    @classmethod
1374
    def get_comic_info(cls, soup, link):
1375
        """Get information about a particular comics."""
1376
        url = cls.get_url_from_archive_element(link)
1377
        title = link.string
1378
        year, month, day = [int(s) for s in cls.comic_link_re.match(url).groups()]
1379
        img = soup.find('div', id='comic').find('img')
1380
        assert img['alt'] == title
1381
        return {
1382
            'title': title,
1383
            'day': day,
1384
            'month': month,
1385
            'year': year,
1386
            'img': [img['src']],
1387
        }
1388
1389
1390
class CalvinAndHobbes(GenericComic):
@@ 1427-1448 (lines=22) @@
1424
1425
1426
class AbstruseGoose(GenericListableComic):
1427
    """Class to retrieve AbstruseGoose Comics."""
1428
    name = 'abstruse'
1429
    long_name = 'Abstruse Goose'
1430
    url = 'http://abstrusegoose.com'
1431
    get_url_from_archive_element = get_href
1432
    comic_url_re = re.compile('^%s/([0-9]*)$' % url)
1433
    comic_img_re = re.compile('^%s/strips/.*' % url)
1434
1435
    @classmethod
1436
    def get_archive_elements(cls):
1437
        archive_url = urljoin_wrapper(cls.url, 'archive')
1438
        return get_soup_at_url(archive_url).find_all('a', href=cls.comic_url_re)
1439
1440
    @classmethod
1441
    def get_comic_info(cls, soup, archive_elt):
1442
        comic_url = cls.get_url_from_archive_element(archive_elt)
1443
        num = int(cls.comic_url_re.match(comic_url).groups()[0])
1444
        return {
1445
            'num': num,
1446
            'title': archive_elt.string,
1447
            'img': [soup.find('img', src=cls.comic_img_re)['src']]
1448
        }
1449
1450
1451
class PhDComics(GenericNavigableComic):
@@ 2037-2060 (lines=24) @@
2034
2035
2036
class PoorlyDrawnLines(GenericListableComic):
2037
    """Class to retrieve Poorly Drawn Lines comics."""
2038
    # Also on http://pdlcomics.tumblr.com
2039
    name = 'poorlydrawn'
2040
    long_name = 'Poorly Drawn Lines'
2041
    url = 'https://www.poorlydrawnlines.com'
2042
    _categories = ('POORLYDRAWN', )
2043
    get_url_from_archive_element = get_href
2044
2045
    @classmethod
2046
    def get_comic_info(cls, soup, link):
2047
        """Get information about a particular comics."""
2048
        imgs = soup.find('div', class_='post').find_all('img')
2049
        assert len(imgs) <= 1
2050
        return {
2051
            'img': [i['src'] for i in imgs],
2052
            'title': imgs[0].get('title', "") if imgs else "",
2053
        }
2054
2055
    @classmethod
2056
    def get_archive_elements(cls):
2057
        archive_url = urljoin_wrapper(cls.url, 'archive')
2058
        url_re = re.compile('^%s/comic/.' % cls.url)
2059
        return reversed(get_soup_at_url(archive_url).find_all('a', href=url_re))
2060
2061
2062
class LoadingComics(GenericNavigableComic):
2063
    """Class to retrieve Loading Artist comics."""