Code Duplication    Length = 19-20 lines in 2 locations

comics.py 2 locations

@@ 2010-2028 (lines=19) @@
2007
        return reversed(get_soup_at_url(archive_url).find_all('td', class_='archive-title'))
2008
2009
    @classmethod
2010
    def get_url_from_archive_element(cls, td):
2011
        return td.find('a')['href']
2012
2013
    @classmethod
2014
    def get_comic_info(cls, soup, td):
2015
        """Get information about a particular comics."""
2016
        url = cls.get_url_from_archive_element(td)
2017
        title = td.find('a').string
2018
        month_and_day = td.previous_sibling.string
2019
        link_re = re.compile('^%s/([0-9]+)/' % cls.url)
2020
        year = link_re.match(url).groups()[0]
2021
        date_str = month_and_day + ' ' + year
2022
        day = string_to_date(date_str, '%b %d %Y')
2023
        imgs = [soup.find('div', id='comic').find('img')]
2024
        assert len(imgs) == 1, imgs
2025
        assert all(i['title'] == i['alt'] == title for i in imgs)
2026
        return {
2027
            'month': day.month,
2028
            'year': day.year,
2029
            'day': day.day,
2030
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
2031
            'title': title,
@@ 2418-2437 (lines=20) @@
2415
    def get_url_from_archive_element(cls, tr):
2416
        """Get url corresponding to an archive element."""
2417
        _, td_comic, td_date, _ = tr.find_all('td')
2418
        link = td_comic.find('a')
2419
        return urljoin_wrapper(cls.url, link['href'])
2420
2421
    @classmethod
2422
    def get_comic_info(cls, soup, tr):
2423
        """Get information about a particular comics."""
2424
        td_num, td_comic, td_date, _ = tr.find_all('td')
2425
        num = int(td_num.string)
2426
        link = td_comic.find('a')
2427
        title = link.string
2428
        imgs = soup.find_all('img', id='comic_image')
2429
        date_str = td_date.string
2430
        day = string_to_date(remove_st_nd_rd_th_from_date(date_str), "%B %d, %Y, %I:%M %p")
2431
        assert len(imgs) == 1, imgs
2432
        assert all(i.get('alt') == i.get('title') for i in imgs)
2433
        return {
2434
            'num': num,
2435
            'title': title,
2436
            'alt': imgs[0].get('alt', ''),
2437
            'img': [i['src'] for i in imgs],
2438
            'month': day.month,
2439
            'year': day.year,
2440
            'day': day.day,