Code Duplication    Length = 23-27 lines in 3 locations

comics.py 3 locations

@@ 1431-1457 (lines=27) @@
1428
        }
1429
1430
1431
class ButterSafe(GenericListableComic):
1432
    """Class to retrieve Butter Safe comics."""
1433
    name = 'butter'
1434
    long_name = 'ButterSafe'
1435
    url = 'http://buttersafe.com'
1436
    get_url_from_archive_element = get_href
1437
    comic_link_re = re.compile('^%s/([0-9]*)/([0-9]*)/([0-9]*)/.*' % url)
1438
1439
    @classmethod
1440
    def get_archive_elements(cls):
1441
        archive_url = urljoin_wrapper(cls.url, 'archive/')
1442
        return reversed(get_soup_at_url(archive_url).find_all('a', href=cls.comic_link_re))
1443
1444
    @classmethod
1445
    def get_comic_info(cls, soup, link):
1446
        """Get information about a particular comics."""
1447
        url = cls.get_url_from_archive_element(link)
1448
        title = link.string
1449
        year, month, day = [int(s) for s in cls.comic_link_re.match(url).groups()]
1450
        img = soup.find('div', id='comic').find('img')
1451
        assert img['alt'] == title
1452
        return {
1453
            'title': title,
1454
            'day': day,
1455
            'month': month,
1456
            'year': year,
1457
            'img': [img['src']],
1458
        }
1459
1460
@@ 2427-2451 (lines=25) @@
2424
        }
2425
2426
2427
class JuliasDrawings(GenericListableComic):
2428
    """Class to retrieve Julia's Drawings."""
2429
    name = 'julia'
2430
    long_name = "Julia's Drawings"
2431
    url = 'https://drawings.jvns.ca'
2432
    get_url_from_archive_element = get_href
2433
2434
    @classmethod
2435
    def get_archive_elements(cls):
2436
        div = get_soup_at_url(cls.url).find('div', class_='drawings')
2437
        return reversed(div.find_all('a'))
2438
2439
    @classmethod
2440
    def get_comic_info(cls, soup, archive_elt):
2441
        """Get information about a particular comics."""
2442
        date_str = soup.find('meta', property='og:article:published_time')['content'][:10]
2443
        day = string_to_date(date_str, "%Y-%m-%d")
2444
        title = soup.find('h3', class_='p-post-title').string
2445
        imgs = soup.find('section', class_='post-content').find_all('img')
2446
        return {
2447
            'title': title,
2448
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
2449
            'month': day.month,
2450
            'year': day.year,
2451
            'day': day.day,
2452
        }
2453
2454
@@ 1497-1519 (lines=23) @@
1494
                        last_date = comic_date
1495
1496
1497
class AbstruseGoose(GenericListableComic):
1498
    """Class to retrieve AbstruseGoose Comics."""
1499
    name = 'abstruse'
1500
    long_name = 'Abstruse Goose'
1501
    url = 'http://abstrusegoose.com'
1502
    get_url_from_archive_element = get_href
1503
    comic_url_re = re.compile('^%s/([0-9]*)$' % url)
1504
    comic_img_re = re.compile('^%s/strips/.*' % url)
1505
1506
    @classmethod
1507
    def get_archive_elements(cls):
1508
        archive_url = urljoin_wrapper(cls.url, 'archive')
1509
        return get_soup_at_url(archive_url).find_all('a', href=cls.comic_url_re)
1510
1511
    @classmethod
1512
    def get_comic_info(cls, soup, archive_elt):
1513
        comic_url = cls.get_url_from_archive_element(archive_elt)
1514
        num = int(cls.comic_url_re.match(comic_url).groups()[0])
1515
        imgs = soup.find_all('img', src=cls.comic_img_re)
1516
        return {
1517
            'num': num,
1518
            'title': archive_elt.string,
1519
            'img': [i['src'] for i in imgs],
1520
        }
1521
1522