Code Duplication    Length = 22-27 lines in 2 locations

comics.py 2 locations

@@ 1309-1335 (lines=27) @@
1306
            'title': img.get('title'),
1307
            'text': text,
1308
            'num': num,
1309
        }
1310
1311
1312
class ButterSafe(GenericListableComic):
1313
    """Class to retrieve Butter Safe comics."""
1314
    name = 'butter'
1315
    long_name = 'ButterSafe'
1316
    url = 'http://buttersafe.com'
1317
    get_url_from_archive_element = get_href
1318
    comic_link_re = re.compile('^%s/([0-9]*)/([0-9]*)/([0-9]*)/.*' % url)
1319
1320
    @classmethod
1321
    def get_archive_elements(cls):
1322
        archive_url = urljoin_wrapper(cls.url, 'archive/')
1323
        return reversed(get_soup_at_url(archive_url).find_all('a', href=cls.comic_link_re))
1324
1325
    @classmethod
1326
    def get_comic_info(cls, soup, link):
1327
        """Get information about a particular comics."""
1328
        url = cls.get_url_from_archive_element(link)
1329
        title = link.string
1330
        year, month, day = [int(s) for s in cls.comic_link_re.match(url).groups()]
1331
        img = soup.find('div', id='comic').find('img')
1332
        assert img['alt'] == title
1333
        return {
1334
            'title': title,
1335
            'day': day,
1336
            'month': month,
1337
            'year': year,
1338
            'img': [img['src']],
@@ 1374-1395 (lines=22) @@
1371
                            'day': int(day),
1372
                            'img': ['%s%s/%s/%s' % (cls.url, year, month, img_src)],
1373
                        }
1374
                        last_date = comic_date
1375
1376
1377
class AbstruseGoose(GenericListableComic):
1378
    """Class to retrieve AbstruseGoose Comics."""
1379
    name = 'abstruse'
1380
    long_name = 'Abstruse Goose'
1381
    url = 'http://abstrusegoose.com'
1382
    get_url_from_archive_element = get_href
1383
    comic_url_re = re.compile('^%s/([0-9]*)$' % url)
1384
    comic_img_re = re.compile('^%s/strips/.*' % url)
1385
1386
    @classmethod
1387
    def get_archive_elements(cls):
1388
        archive_url = urljoin_wrapper(cls.url, 'archive')
1389
        return get_soup_at_url(archive_url).find_all('a', href=cls.comic_url_re)
1390
1391
    @classmethod
1392
    def get_comic_info(cls, soup, archive_elt):
1393
        comic_url = cls.get_url_from_archive_element(archive_elt)
1394
        num = int(cls.comic_url_re.match(comic_url).groups()[0])
1395
        return {
1396
            'num': num,
1397
            'title': archive_elt.string,
1398
            'img': [soup.find('img', src=cls.comic_img_re)['src']]