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