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