|
@@ 4666-4682 (lines=17) @@
|
| 4663 |
|
link_re = re.compile('^/comics/classic/([0-9]+)$') |
| 4664 |
|
|
| 4665 |
|
|
| 4666 |
|
class GenericGoComic(GenericNavigableComic): |
| 4667 |
|
"""Generic class to handle the logic common to comics from gocomics.com.""" |
| 4668 |
|
_categories = ('GOCOMIC', ) |
| 4669 |
|
|
| 4670 |
|
@classmethod |
| 4671 |
|
def get_first_comic_link(cls): |
| 4672 |
|
"""Get link to first comics.""" |
| 4673 |
|
return get_soup_at_url(cls.url).find('a', class_='fa btn btn-outline-default btn-circle fa-backward sm ') |
| 4674 |
|
|
| 4675 |
|
@classmethod |
| 4676 |
|
def get_navi_link(cls, last_soup, next_): |
| 4677 |
|
"""Get link to next or previous comic.""" |
| 4678 |
|
PREV = 'fa btn btn-outline-default btn-circle fa-caret-left js-previous-comic sm ' |
| 4679 |
|
NEXT = 'fa btn btn-outline-default btn-circle fa-caret-right js-next-comic hidden-sm-up sm ' |
| 4680 |
|
return last_soup.find('a', class_=NEXT if next_ else PREV) |
| 4681 |
|
|
| 4682 |
|
@classmethod |
| 4683 |
|
def get_url_from_link(cls, link): |
| 4684 |
|
gocomics = 'http://www.gocomics.com' |
| 4685 |
|
return urljoin_wrapper(gocomics, link['href']) |
|
@@ 763-778 (lines=16) @@
|
| 760 |
|
get_first_comic_link = get_div_navfirst_a |
| 761 |
|
get_navi_link = get_link_rel_next |
| 762 |
|
get_url_from_link = join_cls_url_to_href |
| 763 |
|
|
| 764 |
|
@classmethod |
| 765 |
|
def get_comic_info(cls, soup, link): |
| 766 |
|
"""Get information about a particular comics.""" |
| 767 |
|
short_url_re = re.compile('^%s/\\?p=([0-9]*)' % cls.url) |
| 768 |
|
short_url = cls.get_url_from_link(soup.find('link', rel='shortlink')) |
| 769 |
|
num = int(short_url_re.match(short_url).groups()[0]) |
| 770 |
|
imgs = soup.find('div', id='comic').find_all('img') |
| 771 |
|
assert len(imgs) == 1 |
| 772 |
|
title = imgs[0]['alt'] |
| 773 |
|
title2 = imgs[0]['title'] |
| 774 |
|
return { |
| 775 |
|
'short_url': short_url, |
| 776 |
|
'title': title, |
| 777 |
|
'title2': title2, |
| 778 |
|
'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs], |
| 779 |
|
'num': num, |
| 780 |
|
} |
| 781 |
|
|