~dosage-dev/dosage/test-mode

« back to all changes in this revision

Viewing changes to dosage/plugins/uc.py

  • Committer: ns
  • Date: 2009-12-01 06:56:33 UTC
  • Revision ID: ns@ww1aviationlinks.cjb.net-20091201065633-7j81kj7ma04n3005
S plugin added SailorsunOrg SchoolBites SodiumEyes StrawberryDeathCake and Heard, Sinfest moved out of KeenSpot

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from re import compile, IGNORECASE, sub
2
 
 
3
 
from dosage.helpers import BasicScraper
4
 
from dosage.util import fetchManyMatches, fetchUrl
5
 
 
6
 
 
7
 
class UClickScraper(BasicScraper):
8
 
    abstract = True
9
 
 
10
 
    homepage = 'http://content.uclick.com/a2z.html'
11
 
    baseUrl = 'http://www.uclick.com/client/zzz/%s/'
12
 
    imageUrl = property(lambda self: self.latestUrl + '%s/')
13
 
    imageSearch = compile(r'<img.+?src="(/feature/\d{2}/\d{2}/\d{2}/[^"]+\.gif|http://images\.ucomics\.com/comics/\w+/\d{4}/[^"]+\.gif)">', IGNORECASE)
14
 
    prevSearch = compile(r'<a href="(/client/zzz/\w+/\d{4}/\d{2}/\d{2}/)">Previous date', IGNORECASE)
15
 
    help = 'Index format: yyyy/mm/dd'
16
 
 
17
 
    def starter(cls):
18
 
        return cls.baseUrl % (cls.shortName,)
19
 
 
20
 
    @classmethod
21
 
    def fetchSubmodules(cls):
22
 
        exclusions = (
23
 
            'index',
24
 
            )
25
 
 
26
 
        submoduleSearch = compile(r'(<A HREF="http://content.uclick.com/content/\w+.html">[^>]+?</a>)', IGNORECASE)
27
 
        partsMatch = compile(r'<A HREF="http://content.uclick.com/content/(\w+?).html">([^>]+?)</a>', IGNORECASE)
28
 
        matches = fetchManyMatches(cls.homepage, (submoduleSearch,))[0]
29
 
        possibles = [partsMatch.match(match).groups() for match in matches]
30
 
 
31
 
        def normalizeName(name):
32
 
            name = sub(r'&(.)acute;', r'\1', name).title()
33
 
            return ''.join([c for c in name if c.isalnum()])
34
 
 
35
 
        def fetchSubmodule(module):
36
 
            try:
37
 
                return fetchUrl(cls.baseUrl % module, cls.imageSearch)
38
 
            except:
39
 
                return False
40
 
 
41
 
        return [normalizeName(name) for part, name in possibles if part not in exclusions and fetchSubmodule(part)]
42
 
 
43
 
 
44
 
def uclick(comics):
45
 
    return dict((name, UClickScraper.make('UClick/' + name, shortName=shortName))
46
 
                for name, shortName in comics.iteritems())
47
 
 
48
 
comics = {
49
 
    '9To5': 'tmntf',
50
 
    'AdamHome': 'ad',
51
 
    'Agnes': 'cragn',
52
 
    'AlcarazLalo': 'la',
53
 
    'AlcarazLaloSpanish': 'spla',
54
 
    'AndersonNick': 'wpnan',
55
 
    'AndyCapp': 'crcap',
56
 
    'AnimalCrackers': 'tmani',
57
 
    'Annie': 'tmann',
58
 
    'AsayChuck': 'crcas',
59
 
    'AskShagg': 'crask',
60
 
    'AuthTony': 'ta',
61
 
    'BadReporter': 'bad',
62
 
    'Baldo': 'ba',
63
 
    'BaldoSpanish': 'be',
64
 
    'BallardStreet': 'crbal',
65
 
    'BC': 'crbc',
66
 
    'BCSpanish': 'crbcs',
67
 
    'BensonLisa': 'wplbe',
68
 
    'BensonSteve': 'crsbe',
69
 
    'BigTop': 'bt',
70
 
    'Biographic': 'biov',
71
 
    'BobTheSquirrel': 'bob',
72
 
    'BokChip': 'crcbo',
73
 
    'BoNanas': 'bon',
74
 
    'BoondocksThe': 'bo',
75
 
    'BottomLiners': 'tmbot',
76
 
    'BoundAndGagged': 'tmbou',
77
 
    'Brainwaves': 'bwv',
78
 
    'BrendaStarr': 'tmbre',
79
 
    'BrewsterRockit': 'tmrkt',
80
 
    'BroomHilda': 'tmbro',
81
 
    'Candorville': 'cand',
82
 
    'CarlsonStuart': 'sc',
83
 
    'CatalinoKen': 'crkca',
84
 
    'Cathy': 'ca',
85
 
    'CathySpanish': 'spca',
86
 
    'CEstLaVie': 'clv',
87
 
    'CityThe': 'derf',
88
 
    'ClearBlueWater': 'cbw',
89
 
    'Cleats': 'cle',
90
 
    'CloseToHome': 'cl',
91
 
    'CompuToon': 'tmcom',
92
 
    'Condorito': 'cond',
93
 
    'ConradPaul': 'tmpco',
94
 
    'Cornered': 'co',
95
 
    'DanzigerJeff': 'jd',
96
 
    'DaviesMatt': 'tmmda',
97
 
    'DeepCover': 'deep',
98
 
    'DeeringJohn': 'crjde',
99
 
    'DickTracy': 'tmdic',
100
 
    'DinetteSetThe': 'crdin',
101
 
    'DogEatDoug': 'crdog',
102
 
    'DonWright': 'tmdow',
103
 
    'Doodles': 'tmdoo',
104
 
    'Doonesbury': 'db',
105
 
    'DuplexThe': 'dp',
106
 
    'ElderberriesThe': 'eld',
107
 
    'FacesInTheNews': 'kw',
108
 
    'FlightDeck': 'crfd',
109
 
    'FloAndFriends': 'crflo',
110
 
    'FlyingMccoysThe': 'fmc',
111
 
    'ForBetterOrForWorse': 'fb',
112
 
    'ForHeavenSSake': 'crfhs',
113
 
    'Foxtrot': 'ft',
114
 
    'FoxtrotSpanish': 'spft',
115
 
    'FrankAndErnest': 'fa',
116
 
    'FredBassetSpanish': 'spfba',
117
 
    'FredBasset': 'tmfba',
118
 
    'FrogApplause': 'frog',
119
 
    'FuscoBrothersThe': 'fu',
120
 
    'Garfield': 'ga',
121
 
    'GarfieldSpanish': 'gh',
122
 
    'GasolineAlley': 'tmgas',
123
 
    'GaturroSpanish': 'spgat',
124
 
    'GilThorp': 'tmgil',
125
 
    'GingerMeggs': 'gin',
126
 
    'GingerMeggsSpanish': 'spgin',
127
 
    'GirlsAndSports': 'crgis',
128
 
    'GorrellBob': 'crbgo',
129
 
    'HammondBruce': 'hb',
130
 
    'HandelsmanWalt': 'tmwha',
131
 
    'HeartOfTheCity': 'hc',
132
 
    'Heathcliff': 'crhea',
133
 
    'HeathcliffSpanish': 'crhes',
134
 
    'HerbAndJamaal': 'crher',
135
 
    'HigginsJack': 'jh',
136
 
    'HorseyDavid': 'tmdho',
137
 
    'Housebroken': 'tmhou',
138
 
    'HubertAndAbby': 'haa',
139
 
    'IdiotBox': 'ibox',
140
 
    'InkPen': 'ink',
141
 
    'InTheBleachers': 'bl',
142
 
    'JamesBondSpanish': 'spjb',
143
 
    'JonesClay': 'crcjo',
144
 
    'KallaugherKevin': 'cwkal',
145
 
    'KChroniclesThe': 'kk',
146
 
    'KelleySteve': 'crske',
147
 
    'Kudzu': 'tmkud',
148
 
    'LaCucaracha': 'lc',
149
 
    'LibertyMeadows': 'crlib',
150
 
    'Lio': 'lio',
151
 
    'LocherDick': 'tmdlo',
152
 
    'LooseParts': 'tmloo',
153
 
    'LostSheep': 'lost',
154
 
    'LoweChan': 'tmclo',
155
 
    'LuckovichMike': 'crmlu',
156
 
    'LuckyCow': 'luc',
157
 
    'MarletteDoug': 'tmdma',
158
 
    'MccoyGlenn': 'gm',
159
 
    'MeaningOfLilaThe': 'crlil',
160
 
    'MeehanStreak': 'tmmee',
161
 
    'MiddletonsThe': 'tmmid',
162
 
    'MinimumSecurity': 'ms',
163
 
    'ModestyBlaiseSpanish': 'spmb',
164
 
    'Momma': 'crmom',
165
 
    'MorinJim': 'cwjmo',
166
 
    'MuttJeffSpanish': 'spmut',
167
 
    'NaturalSelection': 'crns',
168
 
    'NestHeads': 'cpnst',
169
 
    'Neurotica': 'neu',
170
 
    'NonSequitur': 'nq',
171
 
    'OhmanJack': 'tmjoh',
172
 
    'OliphantPat': 'po',
173
 
    'OnAClaireDay': 'crocd',
174
 
    'OneBigHappy': 'crobh',
175
 
    'OtherCoastThe': 'crtoc',
176
 
    'OutOfTheGenePool': 'wpgen',
177
 
    'Overboard': 'ob',
178
 
    'OverboardSpanish': 'spob',
179
 
    'PepeSpanish': 'sppep',
180
 
    'PettJoel': 'jp',
181
 
    'Pickles': 'wppic',
182
 
    'Pluggers': 'tmplu',
183
 
    'PoochCafe': 'poc',
184
 
    'PoochCafeSpanish': 'sppoc',
185
 
    'PopCulture': 'pop',
186
 
    'PowellDwane': 'crdpo',
187
 
    'Preteena': 'pr',
188
 
    'PricklyCity': 'prc',
189
 
    'QuigmansThe': 'tmqui',
190
 
    'RallComic': 'tr',
191
 
    'RealLifeAdventures': 'rl',
192
 
    'RedAndRover': 'wpred',
193
 
    'RedMeat': 'red',
194
 
    'ReynoldsUnwrapped': 'rw',
195
 
    'RonaldinhoGaucho': 'ron',
196
 
    'RonaldinhoGauchoSpanish': 'spron',
197
 
    'Rubes': 'crrub',
198
 
    'SackSteve': 'tmssa',
199
 
    'SargentBen': 'bs',
200
 
    'SargentBenSpanish': 'spbs',
201
 
    'SendHelp': 'send',
202
 
    'ShenemanDrew': 'tmdsh',
203
 
    'Shoecabbage': 'shcab',
204
 
    'Shoe': 'tmsho',
205
 
    'SigmundSpanish': 'spsig',
206
 
    'Slowpoke': 'slow',
207
 
    'SmallWorld': 'small',
208
 
    'SpaceIsThePlace': 'sitp',
209
 
    'SpeedBump': 'crspe',
210
 
    'StateOfTheUnion': 'crsou',
211
 
    'StayskalWayne': 'tmwst',
212
 
    'StoneSoup': 'ss',
213
 
    'StrangeBrew': 'crstr',
214
 
    'SummersDana': 'tmdsu',
215
 
    'SuttonImpact': 'stn',
216
 
    'Sylvia': 'tmsyl',
217
 
    'SzepPaul': 'crpsz',
218
 
    'TankMcnamara': 'tm',
219
 
    'TeenageMutantNinjaTurtles': 'tmnt',
220
 
    'TelnaesAnn': 'tmate',
221
 
    'TheArgyleSweater': 'tas',
222
 
    'ThePinkPanther': 'tmpnk',
223
 
    'TheWizardOfId': 'crwiz',
224
 
    'TheWizardOfIdSpanish': 'crwis',
225
 
    'ThInk': 'think',
226
 
    'ThroughThickAndThin': 'cpthk',
227
 
    'TinySepuku': 'tiny',
228
 
    'TolesTom': 'tt',
229
 
    'TomTheDancingBug': 'td',
230
 
    'TooMuchCoffeeMan': 'tmcm',
231
 
    'Trevor': 'trev',
232
 
    'TutelandiaSpanish': 'sptut',
233
 
    'VarvelGary': 'crgva',
234
 
    'WassermanDan': 'tmdwa',
235
 
    'WatchYourHead': 'wpwyh',
236
 
    'Waylay': 'min',
237
 
    'WeePals': 'crwee',
238
 
    'WinnieThePooh': 'crwin',
239
 
    'WorkingItOut': 'crwio',
240
 
    'YennySpanish': 'spyen',
241
 
    'Yenny': 'yen',
242
 
    'ZackHill': 'crzhi',
243
 
    'ZiggySpanish': 'spzi',
244
 
    'Ziggy': 'zi',
245
 
    }
246
 
 
247
 
globals().update(uclick(comics))