Code Duplication    Length = 22-27 lines in 2 locations

comics.py 2 locations

@@ 1387-1413 (lines=27) @@
1384
        }
1385
1386
1387
class ButterSafe(GenericListableComic):
1388
    """Class to retrieve Butter Safe comics."""
1389
    name = 'butter'
1390
    long_name = 'ButterSafe'
1391
    url = 'http://buttersafe.com'
1392
    get_url_from_archive_element = get_href
1393
    comic_link_re = re.compile('^%s/([0-9]*)/([0-9]*)/([0-9]*)/.*' % url)
1394
1395
    @classmethod
1396
    def get_archive_elements(cls):
1397
        archive_url = urljoin_wrapper(cls.url, 'archive/')
1398
        return reversed(get_soup_at_url(archive_url).find_all('a', href=cls.comic_link_re))
1399
1400
    @classmethod
1401
    def get_comic_info(cls, soup, link):
1402
        """Get information about a particular comics."""
1403
        url = cls.get_url_from_archive_element(link)
1404
        title = link.string
1405
        year, month, day = [int(s) for s in cls.comic_link_re.match(url).groups()]
1406
        img = soup.find('div', id='comic').find('img')
1407
        assert img['alt'] == title
1408
        return {
1409
            'title': title,
1410
            'day': day,
1411
            'month': month,
1412
            'year': year,
1413
            'img': [img['src']],
1414
        }
1415
1416
@@ 1453-1474 (lines=22) @@
1450
                        last_date = comic_date
1451
1452
1453
class AbstruseGoose(GenericListableComic):
1454
    """Class to retrieve AbstruseGoose Comics."""
1455
    name = 'abstruse'
1456
    long_name = 'Abstruse Goose'
1457
    url = 'http://abstrusegoose.com'
1458
    get_url_from_archive_element = get_href
1459
    comic_url_re = re.compile('^%s/([0-9]*)$' % url)
1460
    comic_img_re = re.compile('^%s/strips/.*' % url)
1461
1462
    @classmethod
1463
    def get_archive_elements(cls):
1464
        archive_url = urljoin_wrapper(cls.url, 'archive')
1465
        return get_soup_at_url(archive_url).find_all('a', href=cls.comic_url_re)
1466
1467
    @classmethod
1468
    def get_comic_info(cls, soup, archive_elt):
1469
        comic_url = cls.get_url_from_archive_element(archive_elt)
1470
        num = int(cls.comic_url_re.match(comic_url).groups()[0])
1471
        return {
1472
            'num': num,
1473
            'title': archive_elt.string,
1474
            'img': [soup.find('img', src=cls.comic_img_re)['src']]
1475
        }
1476
1477