@@ 1327-1353 (lines=27) @@ | ||
1324 | img = soup.find('div', id='comic').find('img') |
|
1325 | assert img['alt'] == title |
|
1326 | return { |
|
1327 | 'title': title, |
|
1328 | 'day': day, |
|
1329 | 'month': month, |
|
1330 | 'year': year, |
|
1331 | 'img': [img['src']], |
|
1332 | } |
|
1333 | ||
1334 | ||
1335 | class CalvinAndHobbes(GenericComic): |
|
1336 | """Class to retrieve Calvin and Hobbes comics.""" |
|
1337 | # Also on http://www.gocomics.com/calvinandhobbes/ |
|
1338 | name = 'calvin' |
|
1339 | long_name = 'Calvin and Hobbes' |
|
1340 | # This is not through any official webpage but eh... |
|
1341 | url = 'http://marcel-oehler.marcellosendos.ch/comics/ch/' |
|
1342 | ||
1343 | @classmethod |
|
1344 | def get_next_comic(cls, last_comic): |
|
1345 | """Generator to get the next comic. Implementation of GenericComic's abstract method.""" |
|
1346 | last_date = get_date_for_comic( |
|
1347 | last_comic) if last_comic else date(1985, 11, 1) |
|
1348 | link_re = re.compile('^([0-9]*)/([0-9]*)/') |
|
1349 | img_re = re.compile('') |
|
1350 | for link in get_soup_at_url(cls.url).find_all('a', href=link_re): |
|
1351 | url = link['href'] |
|
1352 | year, month = link_re.match(url).groups() |
|
1353 | if date(int(year), int(month), 1) + timedelta(days=31) >= last_date: |
|
1354 | img_re = re.compile('^%s%s([0-9]*)' % (year, month)) |
|
1355 | month_url = urljoin_wrapper(cls.url, url) |
|
1356 | for img in get_soup_at_url(month_url).find_all('img', src=img_re): |
|
@@ 1393-1414 (lines=22) @@ | ||
1390 | 'num': num, |
|
1391 | 'title': archive_elt.string, |
|
1392 | 'img': [soup.find('img', src=cls.comic_img_re)['src']] |
|
1393 | } |
|
1394 | ||
1395 | ||
1396 | class PhDComics(GenericNavigableComic): |
|
1397 | """Class to retrieve PHD Comics.""" |
|
1398 | name = 'phd' |
|
1399 | long_name = 'PhD Comics' |
|
1400 | url = 'http://phdcomics.com/comics/archive.php' |
|
1401 | get_url_from_link = join_cls_url_to_href |
|
1402 | ||
1403 | @classmethod |
|
1404 | def get_first_comic_link(cls): |
|
1405 | """Get link to first comics.""" |
|
1406 | return get_soup_at_url(cls.url).find('img', src='images/first_button.gif').parent |
|
1407 | ||
1408 | @classmethod |
|
1409 | def get_navi_link(cls, last_soup, next_): |
|
1410 | """Get link to next or previous comic.""" |
|
1411 | img = last_soup.find('img', src='images/next_button.gif' if next_ else 'images/prev_button.gif') |
|
1412 | return None if img is None else img.parent |
|
1413 | ||
1414 | @classmethod |
|
1415 | def get_comic_info(cls, soup, link): |
|
1416 | """Get information about a particular comics.""" |
|
1417 | date_str = soup.find('font', face='Arial,Helvetica,Geneva,Swiss,SunSans-Regular', color='white').string.strip() |