2012-06-20 20:41:04 +00:00
|
|
|
# -*- coding: iso-8859-1 -*-
|
|
|
|
# Copyright (C) 2004-2005 Tristan Seligmann and Jonathan Jacobs
|
2013-02-05 18:51:46 +00:00
|
|
|
# Copyright (C) 2012-2013 Bastian Kleineidam
|
2012-11-21 20:57:26 +00:00
|
|
|
|
2012-06-20 19:58:13 +00:00
|
|
|
from re import compile
|
|
|
|
|
2012-10-11 10:03:12 +00:00
|
|
|
from ..scraper import _BasicScraper
|
|
|
|
from ..helpers import bounceStarter
|
2012-11-26 06:13:32 +00:00
|
|
|
from ..util import tagre
|
2012-10-11 10:03:12 +00:00
|
|
|
|
2012-06-20 19:58:13 +00:00
|
|
|
|
|
|
|
class xkcd(_BasicScraper):
|
2013-02-04 20:00:26 +00:00
|
|
|
url = 'http://xkcd.com/'
|
|
|
|
starter = bounceStarter(url, compile(tagre("a", "href", r'(/\d+/)', before="next")))
|
|
|
|
stripUrl = url + '%s/'
|
2013-04-10 21:57:09 +00:00
|
|
|
firstStripUrl = stripUrl % '1'
|
2012-11-26 06:13:32 +00:00
|
|
|
imageSearch = compile(tagre("img", "src", r'(http://imgs\.xkcd\.com/comics/[^"]+)'))
|
|
|
|
prevSearch = compile(tagre("a", "href", r'(/\d+/)', before="prev"))
|
2012-06-20 19:58:13 +00:00
|
|
|
help = 'Index format: n (unpadded)'
|
2013-04-13 06:00:03 +00:00
|
|
|
description = u'A webcomic of romance, sarcasm, math, and language.'
|
2012-06-20 19:58:13 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def namer(cls, imageUrl, pageUrl):
|
2012-11-26 06:13:32 +00:00
|
|
|
index = int(pageUrl.rstrip('/').rsplit('/', 1)[-1])
|
|
|
|
name = imageUrl.rsplit('/', 1)[-1].split('.')[0]
|
|
|
|
return '%03d-%s' % (index, name)
|