Code Duplication    Length = 22-27 lines in 3 locations

comics.py 3 locations

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