Code Duplication    Length = 19-20 lines in 2 locations

comics.py 2 locations

@@ 2300-2319 (lines=20) @@
2297
        """Get url corresponding to an archive element."""
2298
        td_num, td_comic, td_date, _ = tr.find_all('td')
2299
        link = td_comic.find('a')
2300
        return urljoin_wrapper(cls.url, link['href'])
2301
2302
    @classmethod
2303
    def get_comic_info(cls, soup, tr):
2304
        """Get information about a particular comics."""
2305
        td_num, td_comic, td_date, _ = tr.find_all('td')
2306
        num = int(td_num.string)
2307
        link = td_comic.find('a')
2308
        title = link.string
2309
        imgs = soup.find_all('img', id='comic_image')
2310
        date_str = td_date.string
2311
        day = string_to_date(remove_st_nd_rd_th_from_date(date_str), "%B %d, %Y, %I:%M %p")
2312
        assert len(imgs) == 1
2313
        assert all(i.get('alt') == i.get('title') for i in imgs)
2314
        return {
2315
            'num': num,
2316
            'title': title,
2317
            'alt': imgs[0].get('alt', ''),
2318
            'img': [i['src'] for i in imgs],
2319
            'month': day.month,
2320
            'year': day.year,
2321
            'day': day.day,
2322
        }
@@ 1968-1986 (lines=19) @@
1965
1966
    @classmethod
1967
    def get_url_from_archive_element(cls, td):
1968
        return td.find('a')['href']
1969
1970
    @classmethod
1971
    def get_comic_info(cls, soup, td):
1972
        """Get information about a particular comics."""
1973
        url = cls.get_url_from_archive_element(td)
1974
        title = td.find('a').string
1975
        month_and_day = td.previous_sibling.string
1976
        link_re = re.compile('^%s/([0-9]+)/' % cls.url)
1977
        year = link_re.match(url).groups()[0]
1978
        date_str = month_and_day + ' ' + year
1979
        day = string_to_date(date_str, '%b %d %Y')
1980
        imgs = [soup.find('div', id='comic').find('img')]
1981
        assert len(imgs) == 1
1982
        assert all(i['title'] == i['alt'] == title for i in imgs)
1983
        return {
1984
            'month': day.month,
1985
            'year': day.year,
1986
            'day': day.day,
1987
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
1988
            'title': title,
1989
        }