Dynamic type generation helpers.

This commit is contained in:
Bastian Kleineidam 2012-11-26 07:14:02 +01:00
parent 4528894c05
commit d4eee7719d
3 changed files with 10 additions and 87 deletions

View file

@ -1,87 +0,0 @@
# -*- coding: iso-8859-1 -*-
# Copyright (C) 2004-2005 Tristan Seligmann and Jonathan Jacobs
# Copyright (C) 2012 Bastian Kleineidam
from re import compile, sub
from ..scraper import _BasicScraper
from ..util import tagre
def comicsDotCom(name, section):
baseUrl = 'http://www.gocomics.com/'
classname = sub("[^0-9a-zA-Z_]", "", name)
@classmethod
def namer(cls, imageUrl, pageUrl):
prefix, year, month, day = pageUrl.split('/', 3)
return "%s_%s%s%s.gif" % (name, year, month, day)
return type('GoComicsDotCom_%s' % classname,
(_BasicScraper,),
dict(
latestUrl=baseUrl + name,
name='GoComicsDotCom/' + classname,
stripUrl=baseUrl + name + '/%s',
imageSearch=compile(tagre("img", "src", r'(http://assets\.amuniversal\.com/[0-9a-f]+)')),
prevSearch=compile(tagre("a", "href", r'(/[^"]+/\d+/\d+/\d+)', after="prev")),
help='Index format: yyyy/mm/dd',
namer=namer)
)
# http://www.gocomics.com/features
# XXX
# http://www.gocomics.com/explore/editorial_list
# XXX
# http://www.gocomics.com/explore/sherpa_list
# XXX
agnes = comicsDotCom('agnes', 'creators')
andycapp = comicsDotCom('andycapp', 'creators')
barkeaterlake = comicsDotCom('barkeaterlake', 'comics')
bc = comicsDotCom('bc', 'creators')
ben = comicsDotCom('ben', 'comics')
betty = comicsDotCom('betty', 'comics')
bignate = comicsDotCom('bignate', 'comics')
bonanas = comicsDotCom('bonanas', 'wash')
thebornloser = comicsDotCom('the-born-loser', 'comics')
thebuckets = comicsDotCom('thebuckets', 'comics')
candorville = comicsDotCom('candorville', 'wash')
calvinandhobbes = comicsDotCom('calvinandhobbes', 'comics')
chickweed = comicsDotCom('9chickweedlane', 'comics')
committed = comicsDotCom('committed', 'comics')
dilbert = comicsDotCom('dilbert', 'comics')
drabble = comicsDotCom('drabble', 'comics')
floandfriends = comicsDotCom('floandfriends', 'creators')
frazz = comicsDotCom('frazz', 'comics')
geech = comicsDotCom('geech', 'comics')
getfuzzy = comicsDotCom('getfuzzy', 'comics')
graffiti = comicsDotCom('graffiti', 'comics')
grandave = comicsDotCom('grand-avenue', 'comics')
heathcliff = comicsDotCom('heathcliff', 'creators')
herman = comicsDotCom('herman', 'comics')
janesworld = comicsDotCom('janesworld', 'comics')
jumpstart = comicsDotCom('jumpstart', 'comics')
kitandcarlyle = comicsDotCom('kitandcarlyle', 'comics')
luann = comicsDotCom('luann', 'comics')
marmaduke = comicsDotCom('marmaduke', 'comics')
moderatelyconfused = comicsDotCom('moderately-confused', 'comics')
momma = comicsDotCom('momma', 'creators')
monty = comicsDotCom('monty', 'comics')
nancy = comicsDotCom('nancy', 'comics')
offthemark = comicsDotCom('offthemark', 'comics')
onebighappy = comicsDotCom('onebighappy', 'creators')
peanuts = comicsDotCom('peanuts', 'comics')
pearlsbeforeswine = comicsDotCom('pearlsbeforeswine', 'comics')
pibgorn = comicsDotCom('pibgorn', 'comics')
pickles = comicsDotCom('pickles', 'wash')
redandrover = comicsDotCom('redandrover', 'wash')
roseisrose = comicsDotCom('roseisrose', 'comics')
rubes = comicsDotCom('rubes', 'creators')
rudypark = comicsDotCom('rudypark', 'comics')
speedbump = comicsDotCom('speedbump', 'creators')
strangebrew = comicsDotCom('strangebrew', 'creators')
tarzan = comicsDotCom('tarzan', 'comics')
wizardofid = comicsDotCom('wizardofid', 'creators')
workingdaze = comicsDotCom('working-daze', 'comics')
workingitout = comicsDotCom('workingitout', 'creators')

View file

@ -158,3 +158,8 @@ def check_scrapers():
name2 = d[name].get_name()
raise ValueError('Duplicate scrapers %s and %s found' % (name1, name2))
d[name] = scraperclass
def make_scraper(classname, **attributes):
"""Make a new scraper class with given name and attributes."""
return type(classname, (_BasicScraper,), attributes)

View file

@ -324,3 +324,8 @@ def strtimezone():
else:
zone = time.timezone
return "%+04d" % (-zone//3600)
def asciify(name):
"""Remove non-ascii characters from string."""
return re.sub("[^0-9a-zA-Z_]", "", name)