@@ 2393-2412 (lines=20) @@ | ||
2390 | link = td_comic.find('a') |
|
2391 | return urljoin_wrapper(cls.url, link['href']) |
|
2392 | ||
2393 | @classmethod |
|
2394 | def get_comic_info(cls, soup, tr): |
|
2395 | """Get information about a particular comics.""" |
|
2396 | td_num, td_comic, td_date, _ = tr.find_all('td') |
|
2397 | num = int(td_num.string) |
|
2398 | link = td_comic.find('a') |
|
2399 | title = link.string |
|
2400 | imgs = soup.find_all('img', id='comic_image') |
|
2401 | date_str = td_date.string |
|
2402 | day = string_to_date(remove_st_nd_rd_th_from_date(date_str), "%B %d, %Y, %I:%M %p") |
|
2403 | assert len(imgs) == 1, imgs |
|
2404 | assert all(i.get('alt') == i.get('title') for i in imgs) |
|
2405 | return { |
|
2406 | 'num': num, |
|
2407 | 'title': title, |
|
2408 | 'alt': imgs[0].get('alt', ''), |
|
2409 | 'img': [i['src'] for i in imgs], |
|
2410 | 'month': day.month, |
|
2411 | 'year': day.year, |
|
2412 | 'day': day.day, |
|
2413 | } |
|
2414 | ||
2415 | ||
@@ 2010-2028 (lines=19) @@ | ||
2007 | def get_url_from_archive_element(cls, td): |
|
2008 | return td.find('a')['href'] |
|
2009 | ||
2010 | @classmethod |
|
2011 | def get_comic_info(cls, soup, td): |
|
2012 | """Get information about a particular comics.""" |
|
2013 | url = cls.get_url_from_archive_element(td) |
|
2014 | title = td.find('a').string |
|
2015 | month_and_day = td.previous_sibling.string |
|
2016 | link_re = re.compile('^%s/([0-9]+)/' % cls.url) |
|
2017 | year = link_re.match(url).groups()[0] |
|
2018 | date_str = month_and_day + ' ' + year |
|
2019 | day = string_to_date(date_str, '%b %d %Y') |
|
2020 | imgs = [soup.find('div', id='comic').find('img')] |
|
2021 | assert len(imgs) == 1, imgs |
|
2022 | assert all(i['title'] == i['alt'] == title for i in imgs) |
|
2023 | return { |
|
2024 | 'month': day.month, |
|
2025 | 'year': day.year, |
|
2026 | 'day': day.day, |
|
2027 | 'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs], |
|
2028 | 'title': title, |
|
2029 | } |
|
2030 | ||
2031 |