Code Duplication    Length = 19-20 lines in 2 locations

comics.py 2 locations

@@ 2342-2361 (lines=20) @@
2339
        """Get url corresponding to an archive element."""
2340
        _, td_comic, td_date, _ = tr.find_all('td')
2341
        link = td_comic.find('a')
2342
        return urljoin_wrapper(cls.url, link['href'])
2343
2344
    @classmethod
2345
    def get_comic_info(cls, soup, tr):
2346
        """Get information about a particular comics."""
2347
        td_num, td_comic, td_date, _ = tr.find_all('td')
2348
        num = int(td_num.string)
2349
        link = td_comic.find('a')
2350
        title = link.string
2351
        imgs = soup.find_all('img', id='comic_image')
2352
        date_str = td_date.string
2353
        day = string_to_date(remove_st_nd_rd_th_from_date(date_str), "%B %d, %Y, %I:%M %p")
2354
        assert len(imgs) == 1, imgs
2355
        assert all(i.get('alt') == i.get('title') for i in imgs)
2356
        return {
2357
            'num': num,
2358
            'title': title,
2359
            'alt': imgs[0].get('alt', ''),
2360
            'img': [i['src'] for i in imgs],
2361
            'month': day.month,
2362
            'year': day.year,
2363
            'day': day.day,
2364
        }
@@ 1959-1977 (lines=19) @@
1956
1957
    @classmethod
1958
    def get_url_from_archive_element(cls, td):
1959
        return td.find('a')['href']
1960
1961
    @classmethod
1962
    def get_comic_info(cls, soup, td):
1963
        """Get information about a particular comics."""
1964
        url = cls.get_url_from_archive_element(td)
1965
        title = td.find('a').string
1966
        month_and_day = td.previous_sibling.string
1967
        link_re = re.compile('^%s/([0-9]+)/' % cls.url)
1968
        year = link_re.match(url).groups()[0]
1969
        date_str = month_and_day + ' ' + year
1970
        day = string_to_date(date_str, '%b %d %Y')
1971
        imgs = [soup.find('div', id='comic').find('img')]
1972
        assert len(imgs) == 1, imgs
1973
        assert all(i['title'] == i['alt'] == title for i in imgs)
1974
        return {
1975
            'month': day.month,
1976
            'year': day.year,
1977
            'day': day.day,
1978
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
1979
            'title': title,
1980
        }