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