Code Duplication    Length = 23-27 lines in 3 locations

comics.py 3 locations

@@ 1404-1430 (lines=27) @@
1401
        }
1402
1403
1404
class ButterSafe(GenericListableComic):
1405
    """Class to retrieve Butter Safe comics."""
1406
    name = 'butter'
1407
    long_name = 'ButterSafe'
1408
    url = 'http://buttersafe.com'
1409
    get_url_from_archive_element = get_href
1410
    comic_link_re = re.compile('^%s/([0-9]*)/([0-9]*)/([0-9]*)/.*' % url)
1411
1412
    @classmethod
1413
    def get_archive_elements(cls):
1414
        archive_url = urljoin_wrapper(cls.url, 'archive/')
1415
        return reversed(get_soup_at_url(archive_url).find_all('a', href=cls.comic_link_re))
1416
1417
    @classmethod
1418
    def get_comic_info(cls, soup, link):
1419
        """Get information about a particular comics."""
1420
        url = cls.get_url_from_archive_element(link)
1421
        title = link.string
1422
        year, month, day = [int(s) for s in cls.comic_link_re.match(url).groups()]
1423
        img = soup.find('div', id='comic').find('img')
1424
        assert img['alt'] == title
1425
        return {
1426
            'title': title,
1427
            'day': day,
1428
            'month': month,
1429
            'year': year,
1430
            'img': [img['src']],
1431
        }
1432
1433
@@ 2400-2424 (lines=25) @@
2397
        }
2398
2399
2400
class JuliasDrawings(GenericListableComic):
2401
    """Class to retrieve Julia's Drawings."""
2402
    name = 'julia'
2403
    long_name = "Julia's Drawings"
2404
    url = 'https://drawings.jvns.ca'
2405
    get_url_from_archive_element = get_href
2406
2407
    @classmethod
2408
    def get_archive_elements(cls):
2409
        div = get_soup_at_url(cls.url).find('div', class_='drawings')
2410
        return reversed(div.find_all('a'))
2411
2412
    @classmethod
2413
    def get_comic_info(cls, soup, archive_elt):
2414
        """Get information about a particular comics."""
2415
        date_str = soup.find('meta', property='og:article:published_time')['content'][:10]
2416
        day = string_to_date(date_str, "%Y-%m-%d")
2417
        title = soup.find('h3', class_='p-post-title').string
2418
        imgs = soup.find('section', class_='post-content').find_all('img')
2419
        return {
2420
            'title': title,
2421
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
2422
            'month': day.month,
2423
            'year': day.year,
2424
            'day': day.day,
2425
        }
2426
2427
@@ 1470-1492 (lines=23) @@
1467
                        last_date = comic_date
1468
1469
1470
class AbstruseGoose(GenericListableComic):
1471
    """Class to retrieve AbstruseGoose Comics."""
1472
    name = 'abstruse'
1473
    long_name = 'Abstruse Goose'
1474
    url = 'http://abstrusegoose.com'
1475
    get_url_from_archive_element = get_href
1476
    comic_url_re = re.compile('^%s/([0-9]*)$' % url)
1477
    comic_img_re = re.compile('^%s/strips/.*' % url)
1478
1479
    @classmethod
1480
    def get_archive_elements(cls):
1481
        archive_url = urljoin_wrapper(cls.url, 'archive')
1482
        return get_soup_at_url(archive_url).find_all('a', href=cls.comic_url_re)
1483
1484
    @classmethod
1485
    def get_comic_info(cls, soup, archive_elt):
1486
        comic_url = cls.get_url_from_archive_element(archive_elt)
1487
        num = int(cls.comic_url_re.match(comic_url).groups()[0])
1488
        imgs = soup.find_all('img', src=cls.comic_img_re)
1489
        return {
1490
            'num': num,
1491
            'title': archive_elt.string,
1492
            'img': [i['src'] for i in imgs],
1493
        }
1494
1495