Code Duplication    Length = 19-20 lines in 2 locations

comics.py 2 locations

@@ 2223-2242 (lines=20) @@
2220
        """Get url corresponding to an archive element."""
2221
        td_num, td_comic, td_date, _ = tr.find_all('td')
2222
        link = td_comic.find('a')
2223
        return urljoin_wrapper(cls.url, link['href'])
2224
2225
    @classmethod
2226
    def get_comic_info(cls, soup, tr):
2227
        """Get information about a particular comics."""
2228
        td_num, td_comic, td_date, _ = tr.find_all('td')
2229
        num = int(td_num.string)
2230
        link = td_comic.find('a')
2231
        title = link.string
2232
        imgs = soup.find_all('img', id='comic_image')
2233
        date_str = td_date.string
2234
        day = string_to_date(remove_st_nd_rd_th_from_date(date_str), "%B %d, %Y, %I:%M %p")
2235
        assert len(imgs) == 1
2236
        assert all(i.get('alt') == i.get('title') for i in imgs)
2237
        return {
2238
            'num': num,
2239
            'title': title,
2240
            'alt': imgs[0].get('alt', ''),
2241
            'img': [i['src'] for i in imgs],
2242
            'month': day.month,
2243
            'year': day.year,
2244
            'day': day.day,
2245
        }
@@ 1914-1932 (lines=19) @@
1911
1912
    @classmethod
1913
    def get_url_from_archive_element(cls, td):
1914
        return td.find('a')['href']
1915
1916
    @classmethod
1917
    def get_comic_info(cls, soup, td):
1918
        """Get information about a particular comics."""
1919
        url = cls.get_url_from_archive_element(td)
1920
        title = td.find('a').string
1921
        month_and_day = td.previous_sibling.string
1922
        link_re = re.compile('^%s/([0-9]+)/' % cls.url)
1923
        year = link_re.match(url).groups()[0]
1924
        date_str = month_and_day + ' ' + year
1925
        day = string_to_date(date_str, '%b %d %Y')
1926
        imgs = [soup.find('div', id='comic').find('img')]
1927
        assert len(imgs) == 1
1928
        assert all(i['title'] == i['alt'] == title for i in imgs)
1929
        return {
1930
            'month': day.month,
1931
            'year': day.year,
1932
            'day': day.day,
1933
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
1934
            'title': title,
1935
        }