Completed
Push — master ( 26cd44...e70f21 )
by De
52s
created

comics.py (1 issue)

1
#! /usr/bin/python3
2
# vim: set expandtab tabstop=4 shiftwidth=4 :
3
"""Module to retrieve webcomics"""
4
5
from comic_abstract import GenericComic, get_date_for_comic
6
import re
7
from datetime import date, timedelta
8
import datetime
9
from urlfunctions import get_soup_at_url, urljoin_wrapper,\
10
    convert_iri_to_plain_ascii_uri, load_json_at_url, urlopen_wrapper
11
import json
12
import locale
13
import urllib
14
15
DEFAULT_LOCAL = 'en_GB.UTF-8'
16
17
18
class Xkcd(GenericComic):
19
    """Class to retrieve Xkcd comics."""
20
    name = 'xkcd'
21
    long_name = 'xkcd'
22
    url = 'http://xkcd.com'
23
24
    @classmethod
25
    def get_next_comic(cls, last_comic):
26
        """Generator to get the next comic. Implementation of GenericComic's abstract method."""
27
        first_num = last_comic['num'] if last_comic else 0
28
        last_num = load_json_at_url(
29
            urljoin_wrapper(cls.url, 'info.0.json'))['num']
30
31
        for num in range(first_num + 1, last_num + 1):
32
            if num != 404:
33
                json_url = urljoin_wrapper(cls.url, '%d/info.0.json' % num)
34
                comic = load_json_at_url(json_url)
35
                comic['img'] = [comic['img']]
36
                comic['prefix'] = '%d-' % num
37
                comic['json_url'] = json_url
38
                comic['url'] = urljoin_wrapper(cls.url, str(num))
39
                comic['day'] = int(comic['day'])
40
                comic['month'] = int(comic['month'])
41
                comic['year'] = int(comic['year'])
42
                assert comic['num'] == num
43
                yield comic
44
45
46
# Helper functions corresponding to get_url_from_link/get_url_from_archive_element
47
48
49
@classmethod
50
def get_href(cls, link):
51
    """Implementation of get_url_from_link/get_url_from_archive_element."""
52
    return link['href']
53
54
55
@classmethod
56
def join_cls_url_to_href(cls, link):
57
    """Implementation of get_url_from_link/get_url_from_archive_element."""
58
    return urljoin_wrapper(cls.url, link['href'])
59
60
61
class GenericNavigableComic(GenericComic):
62
    """Generic class for "navigable" comics : with first/next arrows.
63
64
    This class applies to comic where previous and next comics can be
65
    accessed from a given comic. Once given a starting point (either
66
    the first comic or the last comic retrieved), it will handle the
67
    navigation, the retrieval of the soup object and the setting of
68
    the 'url' attribute on retrieved comics. This limits a lot the
69
    amount of boilerplate code in the different implementation classes.
70
71
    The method `get_next_comic` methods is implemented in terms of new
72
    more specialized methods to be implemented/overridden:
73
        - get_first_comic_link
74
        - get_navi_link
75
        - get_comic_info
76
        - get_url_from_link
77
    """
78
    _categories = ('NAVIGABLE', )
79
80
    @classmethod
81
    def get_first_comic_link(cls):
82
        """Get link to first comics.
83
84
        Sometimes this can be retrieved of any comic page, sometimes on
85
        the archive page, sometimes it doesn't exist at all and one has
86
        to iterate backward to find it before hardcoding the result found.
87
        """
88
        raise NotImplementedError
89
90
    @classmethod
91
    def get_navi_link(cls, last_soup, next_):
92
        """Get link to next (or previous - for dev purposes) comic."""
93
        raise NotImplementedError
94
95
    @classmethod
96
    def get_comic_info(cls, soup, link):
97
        """Get information about a particular comics."""
98
        raise NotImplementedError
99
100
    @classmethod
101
    def get_url_from_link(cls, link):
102
        """Get url corresponding to a link. Default implementation is similar to get_href."""
103
        return link['href']
104
105
    @classmethod
106
    def get_next_link(cls, last_soup):
107
        """Get link to next comic."""
108
        return cls.get_navi_link(last_soup, True)
109
110
    @classmethod
111
    def get_prev_link(cls, last_soup):
112
        """Get link to previous comic."""
113
        return cls.get_navi_link(last_soup, False)
114
115
    @classmethod
116
    def get_next_comic(cls, last_comic):
117
        """Generic implementation of get_next_comic for navigable comics."""
118
        url = last_comic['url'] if last_comic else None
119
        next_comic = \
120
            cls.get_next_link(get_soup_at_url(url)) \
121
            if url else \
122
            cls.get_first_comic_link()
123
        cls.log("next/first comic will be %s (url is %s)" % (str(next_comic), url))
124
        while next_comic:
125
            prev_url, url = url, cls.get_url_from_link(next_comic)
126
            if prev_url == url:
127
                cls.log("got same url %s" % url)
128
                break
129
            cls.log("about to get %s (%s)" % (url, str(next_comic)))
130
            soup = get_soup_at_url(url)
131
            comic = cls.get_comic_info(soup, next_comic)
132
            if comic is not None:
133
                assert 'url' not in comic
134
                comic['url'] = url
135
                yield comic
136
            next_comic = cls.get_next_link(soup)
137
            cls.log("next comic will be %s" % str(next_comic))
138
139
    @classmethod
140
    def check_first_link(cls):
141
        """Check that navigation to first comic seems to be working - for dev purposes."""
142
        cls.log("about to check first link")
143
        ok = True
144
        firstlink = cls.get_first_comic_link()
145
        if firstlink is None:
146
            print("From %s : no first link" % cls.url)
147
            ok = False
148
        else:
149
            firsturl = cls.get_url_from_link(firstlink)
150
            try:
151
                get_soup_at_url(firsturl)
152
            except urllib.error.HTTPError:
153
                print("From %s : invalid first url" % cls.url)
154
                ok = False
155
        cls.log("checked first link -> returned %d" % ok)
156
        return ok
157
158
    @classmethod
159
    def check_prev_next_links(cls, url):
160
        """Check that navigation to prev/next from a given URL seems to be working - for dev purposes."""
161
        cls.log("about to check prev/next from %s" % url)
162
        ok = True
163
        if url is None:
164
            prevlink, nextlink = None, None
165
        else:
166
            soup = get_soup_at_url(url)
167
            prevlink, nextlink = cls.get_prev_link(soup), cls.get_next_link(soup)
168
        if prevlink is None and nextlink is None:
169
            print("From %s : no previous nor next" % url)
170
            ok = False
171
        else:
172
            if prevlink:
173
                prevurl = cls.get_url_from_link(prevlink)
174
                prevsoup = get_soup_at_url(prevurl)
175
                prevnext = cls.get_url_from_link(cls.get_next_link(prevsoup))
176
                if prevnext != url:
177
                    print("From %s, going backward then forward leads to %s" % (url, prevnext))
178
                    ok = False
179
            if nextlink:
180
                nexturl = cls.get_url_from_link(nextlink)
181
                if nexturl != url:
182
                    nextsoup = get_soup_at_url(nexturl)
183
                    nextprev = cls.get_url_from_link(cls.get_prev_link(nextsoup))
184
                    if nextprev != url:
185
                        print("From %s, going forward then backward leads to %s" % (url, nextprev))
186
                        ok = False
187
        cls.log("checked prev/next from %s -> returned %d" % (url, ok))
188
        return ok
189
190
    @classmethod
191
    def check_navigation(cls, url):
192
        """Check that navigation functions seem to be working - for dev purposes."""
193
        cls.log("about to check navigation from %s" % url)
194
        first = cls.check_first_link()
195
        prevnext = cls.check_prev_next_links(url)
196
        ok = first and prevnext
197
        cls.log("checked navigation from %s -> returned %d" % (url, ok))
198
        return ok
199
200
201
class GenericListableComic(GenericComic):
202
    """Generic class for "listable" comics : with a list of comics (aka 'archive')
203
204
    The method `get_next_comic` methods is implemented in terms of new
205
    more specialized methods to be implemented/overridden:
206
        - get_archive_elements
207
        - get_url_from_archive_element
208
        - get_comic_info
209
    """
210
    _categories = ('LISTABLE', )
211
212
    @classmethod
213
    def get_archive_elements(cls):
214
        """Get the archive elements (iterable)."""
215
        raise NotImplementedError
216
217
    @classmethod
218
    def get_url_from_archive_element(cls, archive_elt):
219
        """Get url corresponding to an archive element."""
220
        raise NotImplementedError
221
222
    @classmethod
223
    def get_comic_info(cls, soup, archive_elt):
224
        """Get information about a particular comics."""
225
        raise NotImplementedError
226
227
    @classmethod
228
    def get_next_comic(cls, last_comic):
229
        """Generic implementation of get_next_comic for listable comics."""
230
        waiting_for_url = last_comic['url'] if last_comic else None
231
        for archive_elt in cls.get_archive_elements():
232
            url = cls.get_url_from_archive_element(archive_elt)
233
            cls.log("considering %s" % url)
234
            if waiting_for_url is None:
235
                cls.log("about to get %s (%s)" % (url, str(archive_elt)))
236
                soup = get_soup_at_url(url)
237
                comic = cls.get_comic_info(soup, archive_elt)
238
                if comic is not None:
239
                    assert 'url' not in comic
240
                    comic['url'] = url
241
                    yield comic
242
            elif waiting_for_url == url:
243
                waiting_for_url = None
244
        if waiting_for_url is not None:
245
            print("Did not find %s : there might be a problem" % waiting_for_url)
246
247
# Helper functions corresponding to get_first_comic_link/get_navi_link
248
249
250
@classmethod
251
def get_link_rel_next(cls, last_soup, next_):
252
    """Implementation of get_navi_link."""
253
    return last_soup.find('link', rel='next' if next_ else 'prev')
254
255
256
@classmethod
257
def get_a_rel_next(cls, last_soup, next_):
258
    """Implementation of get_navi_link."""
259
    return last_soup.find('a', rel='next' if next_ else 'prev')
260
261
262
@classmethod
263
def get_a_navi_navinext(cls, last_soup, next_):
264
    """Implementation of get_navi_link."""
265
    return last_soup.find('a', class_='navi navi-next' if next_ else 'navi navi-prev')
266
267
268
@classmethod
269
def get_a_navi_comicnavnext_navinext(cls, last_soup, next_):
270
    """Implementation of get_navi_link."""
271
    return last_soup.find('a', class_='navi comic-nav-next navi-next' if next_ else 'navi comic-nav-previous navi-prev')
272
273
274
@classmethod
275
def get_a_comicnavbase_comicnavnext(cls, last_soup, next_):
276
    """Implementation of get_navi_link."""
277
    return last_soup.find('a', class_='comic-nav-base comic-nav-next' if next_ else 'comic-nav-base comic-nav-previous')
278
279
280
@classmethod
281
def get_a_navi_navifirst(cls):
282
    """Implementation of get_first_comic_link."""
283
    return get_soup_at_url(cls.url).find('a', class_='navi navi-first')
284
285
286
@classmethod
287
def get_div_navfirst_a(cls):
288
    """Implementation of get_first_comic_link."""
289
    return get_soup_at_url(cls.url).find('div', class_="nav-first").find('a')
290
291
292
@classmethod
293
def get_a_comicnavbase_comicnavfirst(cls):
294
    """Implementation of get_first_comic_link."""
295
    return get_soup_at_url(cls.url).find('a', class_='comic-nav-base comic-nav-first')
296
297
298
@classmethod
299
def simulate_first_link(cls):
300
    """Implementation of get_first_comic_link creating a link-like object from
301
    an URL provided by the class."""
302
    return {'href': cls.first_url}
303
304
305
@classmethod
306
def navigate_to_first_comic(cls):
307
    """Implementation of get_first_comic_link navigating from a user provided
308
    URL to the first comic.
309
310
    Sometimes, the first comic cannot be reached directly so to start
311
    from the first comic one has to go to the previous comic until
312
    there is no previous comics. Once this URL is reached, it
313
    is better to hardcode it but for development purposes, it
314
    is convenient to have an automatic way to find it.
315
    """
316
    url = input("Get starting URL: ")
317
    print(url)
318
    comic = cls.get_prev_link(get_soup_at_url(url))
319
    while comic:
320
        url = cls.get_url_from_link(comic)
321
        print(url)
322
        comic = cls.get_prev_link(get_soup_at_url(url))
323
    return {'href': url}
324
325
326
class GenericEmptyComic(GenericComic):
327
    """Generic class for comics where nothing is to be done.
328
329
    It can be useful to deactivate temporarily comics that do not work
330
    properly by replacing `def MyComic(GenericWhateverComic)` with
331
    `def MyComic(GenericEmptyComic, GenericWhateverComic)`."""
332
    _categories = ('EMPTY', )
333
334
    @classmethod
335
    def get_next_comic(cls, last_comic):
336
        """Implementation of get_next_comic returning no comics."""
337
        cls.log("comic is considered as empty - returning no comic")
338 View Code Duplication
        return []
339
340
341
class ExtraFabulousComics(GenericNavigableComic):
342
    """Class to retrieve Extra Fabulous Comics."""
343
    name = 'efc'
344
    long_name = 'Extra Fabulous Comics'
345
    url = 'http://extrafabulouscomics.com'
346
    get_first_comic_link = get_a_navi_navifirst
347
    get_navi_link = get_link_rel_next
348
349
    @classmethod
350
    def get_comic_info(cls, soup, link):
351
        """Get information about a particular comics."""
352
        img_src_re = re.compile('^%s/wp-content/uploads/' % cls.url)
353
        imgs = soup.find_all('img', src=img_src_re)
354
        title = soup.find('meta', property='og:title')['content']
355
        date_str = soup.find('meta', property='article:published_time')['content'][:10]
356
        day = string_to_date(date_str, "%Y-%m-%d")
357
        return {
358
            'title': title,
359
            'img': [i['src'] for i in imgs],
360
            'month': day.month,
361
            'year': day.year,
362
            'day': day.day,
363
            'prefix': title + '-'
364
        }
365
366
367
class GenericLeMondeBlog(GenericNavigableComic):
368
    """Generic class to retrieve comics from Le Monde blogs."""
369
    _categories = ('LEMONDE', 'FRANCAIS')
370
    get_navi_link = get_link_rel_next
371
    get_first_comic_link = simulate_first_link
372
    first_url = NotImplemented
373
374
    @classmethod
375
    def get_comic_info(cls, soup, link):
376
        """Get information about a particular comics."""
377
        url2 = soup.find('link', rel='shortlink')['href']
378
        title = soup.find('meta', property='og:title')['content']
379
        date_str = soup.find("span", class_="entry-date").string
380
        day = string_to_date(date_str, "%d %B %Y", "fr_FR.utf8")
381
        imgs = soup.find_all('meta', property='og:image')
382
        return {
383
            'title': title,
384
            'url2': url2,
385
            'img': [convert_iri_to_plain_ascii_uri(i['content']) for i in imgs],
386
            'month': day.month,
387
            'year': day.year,
388
            'day': day.day,
389
        }
390
391
392
class ZepWorld(GenericLeMondeBlog):
393
    """Class to retrieve Zep World comics."""
394
    name = "zep"
395
    long_name = "Zep World"
396
    url = "http://zepworld.blog.lemonde.fr"
397
    first_url = "http://zepworld.blog.lemonde.fr/2014/10/31/bientot-le-blog-de-zep/"
398
399
400
class Vidberg(GenericLeMondeBlog):
401
    """Class to retrieve Vidberg comics."""
402
    name = 'vidberg'
403
    long_name = "Vidberg - l'actu en patates"
404
    url = "http://vidberg.blog.lemonde.fr"
405
    # Not the first but I didn't find an efficient way to retrieve it
406
    first_url = "http://vidberg.blog.lemonde.fr/2012/02/09/revue-de-campagne-la-campagne-du-modem-semballe/"
407
408
409
class Plantu(GenericLeMondeBlog):
410
    """Class to retrieve Plantu comics."""
411
    name = 'plantu'
412
    long_name = "Plantu"
413
    url = "http://plantu.blog.lemonde.fr"
414
    first_url = "http://plantu.blog.lemonde.fr/2014/10/28/stress-test-a-bruxelles/"
415
416
417
class XavierGorce(GenericLeMondeBlog):
418
    """Class to retrieve Xavier Gorce comics."""
419
    name = 'gorce'
420
    long_name = "Xavier Gorce"
421
    url = "http://xaviergorce.blog.lemonde.fr"
422
    first_url = "http://xaviergorce.blog.lemonde.fr/2015/01/09/distinction/"
423
424
425
class CartooningForPeace(GenericLeMondeBlog):
426
    """Class to retrieve Cartooning For Peace comics."""
427
    name = 'forpeace'
428
    long_name = "Cartooning For Peace"
429
    url = "http://cartooningforpeace.blog.lemonde.fr"
430
    first_url = "http://cartooningforpeace.blog.lemonde.fr/2014/12/15/bado/"
431
432
433
class Aurel(GenericLeMondeBlog):
434
    """Class to retrieve Aurel comics."""
435
    name = 'aurel'
436
    long_name = "Aurel"
437
    url = "http://aurel.blog.lemonde.fr"
438
    first_url = "http://aurel.blog.lemonde.fr/2014/09/29/le-senat-repasse-a-droite/"
439
440
441
class LesCulottees(GenericLeMondeBlog):
442
    """Class to retrieve Les Culottees comics."""
443
    name = 'culottees'
444
    long_name = 'Les Culottees'
445
    url = "http://lesculottees.blog.lemonde.fr"
446
    first_url = "http://lesculottees.blog.lemonde.fr/2016/01/11/clementine-delait-femme-a-barbe/"
447
448
449
class UneAnneeAuLycee(GenericLeMondeBlog):
450
    """Class to retrieve Une Annee Au Lycee comics."""
451
    name = 'lycee'
452
    long_name = 'Une Annee au Lycee'
453
    url = 'http://uneanneeaulycee.blog.lemonde.fr'
454
    first_url = "http://uneanneeaulycee.blog.lemonde.fr/2016/06/13/la-semaine-du-bac-est-arrivee/"
455
456
457
class Rall(GenericNavigableComic):
458
    """Class to retrieve Ted Rall comics."""
459
    # Also on http://www.gocomics.com/tedrall
460
    name = 'rall'
461
    long_name = "Ted Rall"
462
    url = "http://rall.com/comic"
463
    _categories = ('RALL', )
464
    get_navi_link = get_link_rel_next
465
    get_first_comic_link = simulate_first_link
466
    # Not the first but I didn't find an efficient way to retrieve it
467
    first_url = "http://rall.com/2014/01/30/los-angeles-times-cartoon-well-miss-those-california-flowers"
468
469
    @classmethod
470
    def get_comic_info(cls, soup, link):
471
        """Get information about a particular comics."""
472
        title = soup.find('meta', property='og:title')['content']
473
        author = soup.find("span", class_="author vcard").find("a").string
474
        date_str = soup.find("span", class_="entry-date").string
475
        day = string_to_date(date_str, "%B %d, %Y")
476
        desc = soup.find('meta', property='og:description')['content']
477
        imgs = soup.find('div', class_='entry-content').find_all('img')
478
        imgs = imgs[:-7]  # remove social media buttons
479
        return {
480
            'title': title,
481
            'author': author,
482
            'month': day.month,
483
            'year': day.year,
484
            'day': day.day,
485
            'description': desc,
486
            'img': [i['src'] for i in imgs],
487
        }
488
489
490
class Dilem(GenericNavigableComic):
491
    """Class to retrieve Ali Dilem comics."""
492
    name = 'dilem'
493
    long_name = 'Ali Dilem'
494
    url = 'http://information.tv5monde.com/dilem'
495
    _categories = ('FRANCAIS', )
496
    get_url_from_link = join_cls_url_to_href
497
    get_first_comic_link = simulate_first_link
498
    first_url = "http://information.tv5monde.com/dilem/2004-06-26"
499
500
    @classmethod
501
    def get_navi_link(cls, last_soup, next_):
502
        """Get link to next or previous comic."""
503
        # prev is next / next is prev
504
        li = last_soup.find('li', class_='prev' if next_ else 'next')
505
        return li.find('a') if li else None
506
507
    @classmethod
508
    def get_comic_info(cls, soup, link):
509
        """Get information about a particular comics."""
510
        short_url = soup.find('link', rel='shortlink')['href']
511
        title = soup.find('meta', attrs={'name': 'twitter:title'})['content']
512
        imgs = soup.find_all('meta', property='og:image')
513
        date_str = soup.find('span', property='dc:date')['content']
514
        date_str = date_str[:10]
515
        day = string_to_date(date_str, "%Y-%m-%d")
516
        return {
517
            'short_url': short_url,
518
            'title': title,
519
            'img': [i['content'] for i in imgs],
520
            'day': day.day,
521
            'month': day.month,
522
            'year': day.year,
523
        }
524
525
526
class SpaceAvalanche(GenericNavigableComic):
527
    """Class to retrieve Space Avalanche comics."""
528
    name = 'avalanche'
529
    long_name = 'Space Avalanche'
530
    url = 'http://www.spaceavalanche.com'
531
    get_navi_link = get_link_rel_next
532
533
    @classmethod
534
    def get_first_comic_link(cls):
535
        """Get link to first comics."""
536
        return {'href': "http://www.spaceavalanche.com/2009/02/02/irish-sea/", 'title': "Irish Sea"}
537
538
    @classmethod
539
    def get_comic_info(cls, soup, link):
540
        """Get information about a particular comics."""
541
        url_date_re = re.compile('.*/([0-9]*)/([0-9]*)/([0-9]*)/.*$')
542
        title = link['title']
543
        url = cls.get_url_from_link(link)
544
        year, month, day = [int(s)
545
                            for s in url_date_re.match(url).groups()]
546
        imgs = soup.find("div", class_="entry").find_all("img")
547
        return {
548
            'title': title,
549
            'day': day,
550
            'month': month,
551
            'year': year,
552
            'img': [i['src'] for i in imgs],
553
        }
554
555
556
class ZenPencils(GenericNavigableComic):
557
    """Class to retrieve ZenPencils comics."""
558
    # Also on http://zenpencils.tumblr.com
559
    # Also on http://www.gocomics.com/zen-pencils
560
    name = 'zenpencils'
561
    long_name = 'Zen Pencils'
562
    url = 'http://zenpencils.com'
563
    _categories = ('ZENPENCILS', )
564
    get_navi_link = get_link_rel_next
565
    get_first_comic_link = simulate_first_link
566
    first_url = "http://zenpencils.com/comic/1-ralph-waldo-emerson-make-them-cry/"
567
568
    @classmethod
569
    def get_comic_info(cls, soup, link):
570
        """Get information about a particular comics."""
571
        imgs = soup.find('div', id='comic').find_all('img')
572
        # imgs2 = soup.find_all('meta', property='og:image')
573
        post = soup.find('div', class_='post-content')
574
        author = post.find("span", class_="post-author").find("a").string
575
        title = soup.find('meta', property='og:title')['content']
576
        date_str = post.find('span', class_='post-date').string
577
        day = string_to_date(date_str, "%B %d, %Y")
578
        assert imgs
579
        assert all(i['alt'] == i['title'] for i in imgs)
580
        assert all(i['alt'] in (title, "") for i in imgs)
581
        desc = soup.find('meta', property='og:description')['content']
582
        return {
583
            'title': title,
584
            'description': desc,
585
            'author': author,
586
            'day': day.day,
587
            'month': day.month,
588
            'year': day.year,
589
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
590
        }
591
592
593
class ItsTheTie(GenericNavigableComic):
594
    """Class to retrieve It's the tie comics."""
595
    # Also on http://itsthetie.tumblr.com
596
    # Also on https://tapastic.com/series/itsthetie
597
    name = 'tie'
598
    long_name = "It's the tie"
599
    url = "http://itsthetie.com"
600
    _categories = ('TIE', )
601
    get_first_comic_link = get_div_navfirst_a
602
    get_navi_link = get_a_rel_next
603
604
    @classmethod
605
    def get_comic_info(cls, soup, link):
606
        """Get information about a particular comics."""
607
        title = soup.find('h1', class_='comic-title').find('a').string
608
        date_str = soup.find('header', class_='comic-meta entry-meta').find('a').string
609
        day = string_to_date(date_str, "%B %d, %Y")
610
        # Bonus images may or may not be in meta og:image.
611
        imgs = soup.find_all('meta', property='og:image')
612
        imgs_src = [i['content'] for i in imgs]
613
        bonus = soup.find_all('img', attrs={'data-oversrc': True})
614
        bonus_src = [b['data-oversrc'] for b in bonus]
615
        all_imgs_src = imgs_src + [s for s in bonus_src if s not in imgs_src]
616
        all_imgs_src = [s for s in all_imgs_src if not s.endswith("/2016/01/bonus-panel.png")]
617
        tag_meta = soup.find('meta', property='article:tag')
618
        tags = tag_meta['content'] if tag_meta else ""
619
        return {
620
            'title': title,
621
            'month': day.month,
622
            'year': day.year,
623
            'day': day.day,
624
            'img': all_imgs_src,
625
            'tags': tags,
626
        }
627
628
629
class PenelopeBagieu(GenericNavigableComic):
630
    """Class to retrieve comics from Penelope Bagieu's blog."""
631
    name = 'bagieu'
632
    long_name = 'Ma vie est tout a fait fascinante (Bagieu)'
633
    url = 'http://www.penelope-jolicoeur.com'
634
    _categories = ('FRANCAIS', )
635
    get_navi_link = get_link_rel_next
636
    get_first_comic_link = simulate_first_link
637
    first_url = 'http://www.penelope-jolicoeur.com/2007/02/ma-vie-mon-oeuv.html'
638
639
    @classmethod
640
    def get_comic_info(cls, soup, link):
641
        """Get information about a particular comics."""
642
        date_str = soup.find('h2', class_='date-header').string
643
        day = string_to_date(date_str, "%A %d %B %Y", "fr_FR.utf8")
644
        imgs = soup.find('div', class_='entry-body').find_all('img')
645 View Code Duplication
        title = soup.find('h3', class_='entry-header').string
646
        return {
647
            'title': title,
648
            'img': [i['src'] for i in imgs],
649
            'month': day.month,
650
            'year': day.year,
651
            'day': day.day,
652
        }
653
654
655
class OneOneOneOneComic(GenericNavigableComic):
656
    """Class to retrieve 1111 Comics."""
657
    # Also on http://comics1111.tumblr.com
658
    # Also on https://tapastic.com/series/1111-Comics
659
    name = '1111'
660
    long_name = '1111 Comics'
661
    url = 'http://www.1111comics.me'
662
    _categories = ('ONEONEONEONE', )
663
    get_first_comic_link = get_div_navfirst_a
664
    get_navi_link = get_link_rel_next
665
666
    @classmethod
667
    def get_comic_info(cls, soup, link):
668
        """Get information about a particular comics."""
669
        title = soup.find('h1', class_='comic-title').find('a').string
670
        date_str = soup.find('header', class_='comic-meta entry-meta').find('a').string
671
        day = string_to_date(date_str, "%B %d, %Y")
672
        imgs = soup.find_all('meta', property='og:image')
673
        return {
674
            'title': title,
675
            'month': day.month,
676
            'year': day.year,
677
            'day': day.day,
678
            'img': [i['content'] for i in imgs],
679
        }
680
681
682
class AngryAtNothing(GenericNavigableComic):
683
    """Class to retrieve Angry at Nothing comics."""
684
    # Also on http://tapastic.com/series/Comics-yeah-definitely-comics-
685
    name = 'angry'
686
    long_name = 'Angry At Nothing'
687
    url = 'http://www.angryatnothing.net'
688
    get_first_comic_link = get_div_navfirst_a
689
    get_navi_link = get_a_rel_next
690
691
    @classmethod
692
    def get_comic_info(cls, soup, link):
693
        """Get information about a particular comics."""
694
        title = soup.find('h1', class_='comic-title').find('a').string
695
        date_str = soup.find('header', class_='comic-meta entry-meta').find('a').string
696
        day = string_to_date(date_str, "%B %d, %Y")
697
        imgs = soup.find_all('meta', property='og:image')
698
        return {
699
            'title': title,
700
            'month': day.month,
701
            'year': day.year,
702
            'day': day.day,
703
            'img': [i['content'] for i in imgs],
704
        }
705
706
707
class NeDroid(GenericNavigableComic):
708
    """Class to retrieve NeDroid comics."""
709
    name = 'nedroid'
710
    long_name = 'NeDroid'
711
    url = 'http://nedroid.com'
712
    get_first_comic_link = get_div_navfirst_a
713
    get_navi_link = get_link_rel_next
714
    get_url_from_link = join_cls_url_to_href
715
716
    @classmethod
717
    def get_comic_info(cls, soup, link):
718
        """Get information about a particular comics."""
719
        short_url_re = re.compile('^%s/\\?p=([0-9]*)' % cls.url)
720
        comic_url_re = re.compile('//nedroid.com/comics/([0-9]*)-([0-9]*)-([0-9]*).*')
721
        short_url = cls.get_url_from_link(soup.find('link', rel='shortlink'))
722
        num = int(short_url_re.match(short_url).groups()[0])
723
        imgs = soup.find('div', id='comic').find_all('img')
724
        year, month, day = [int(s) for s in comic_url_re.match(imgs[0]['src']).groups()]
725
        assert len(imgs) == 1
726
        title = imgs[0]['alt']
727
        title2 = imgs[0]['title']
728
        return {
729
            'short_url': short_url,
730
            'title': title,
731
            'title2': title2,
732
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
733
            'day': day,
734
            'month': month,
735
            'year': year,
736
            'num': num,
737
        }
738
739
740
class Garfield(GenericNavigableComic):
741
    """Class to retrieve Garfield comics."""
742
    # Also on http://www.gocomics.com/garfield
743
    name = 'garfield'
744
    long_name = 'Garfield'
745
    url = 'https://garfield.com'
746
    _categories = ('GARFIELD', )
747
    get_first_comic_link = simulate_first_link
748
    first_url = 'https://garfield.com/comic/1978/06/19'
749
750
    @classmethod
751
    def get_navi_link(cls, last_soup, next_):
752
        """Get link to next or previous comic."""
753
        return last_soup.find('a', class_='comic-arrow-right' if next_ else 'comic-arrow-left')
754
755
    @classmethod
756
    def get_comic_info(cls, soup, link):
757
        """Get information about a particular comics."""
758 View Code Duplication
        url = cls.get_url_from_link(link)
759
        date_re = re.compile('^%s/comic/([0-9]*)/([0-9]*)/([0-9]*)' % cls.url)
760
        year, month, day = [int(s) for s in date_re.match(url).groups()]
761
        imgs = soup.find('div', class_='comic-display').find_all('img', class_='img-responsive')
762
        return {
763
            'month': month,
764
            'year': year,
765
            'day': day,
766
            'img': [i['src'] for i in imgs],
767
        }
768
769
770
class Dilbert(GenericNavigableComic):
771
    """Class to retrieve Dilbert comics."""
772
    # Also on http://www.gocomics.com/dilbert-classics
773
    name = 'dilbert'
774
    long_name = 'Dilbert'
775
    url = 'http://dilbert.com'
776
    get_url_from_link = join_cls_url_to_href
777
    get_first_comic_link = simulate_first_link
778
    first_url = 'http://dilbert.com/strip/1989-04-16'
779
780
    @classmethod
781
    def get_navi_link(cls, last_soup, next_):
782
        """Get link to next or previous comic."""
783
        link = last_soup.find('div', class_='nav-comic nav-right' if next_ else 'nav-comic nav-left')
784
        return link.find('a') if link else None
785
786
    @classmethod
787
    def get_comic_info(cls, soup, link):
788
        """Get information about a particular comics."""
789
        title = soup.find('meta', property='og:title')['content']
790
        imgs = soup.find_all('meta', property='og:image')
791
        desc = soup.find('meta', property='og:description')['content']
792
        date_str = soup.find('meta', property='article:publish_date')['content']
793
        day = string_to_date(date_str, "%B %d, %Y")
794
        author = soup.find('meta', property='article:author')['content']
795
        tags = soup.find('meta', property='article:tag')['content']
796
        return {
797
            'title': title,
798
            'description': desc,
799
            'img': [i['content'] for i in imgs],
800
            'author': author,
801
            'tags': tags,
802
            'day': day.day,
803
            'month': day.month,
804
            'year': day.year
805
        }
806
807
808
class VictimsOfCircumsolar(GenericNavigableComic):
809
    """Class to retrieve VictimsOfCircumsolar comics."""
810
    name = 'circumsolar'
811
    long_name = 'Victims Of Circumsolar'
812
    url = 'http://www.victimsofcircumsolar.com'
813
    get_navi_link = get_a_navi_comicnavnext_navinext
814
    get_first_comic_link = simulate_first_link
815
    first_url = 'http://www.victimsofcircumsolar.com/comic/modern-addiction'
816
817
    @classmethod
818
    def get_comic_info(cls, soup, link):
819
        """Get information about a particular comics."""
820
        # Date is on the archive page
821
        title = soup.find_all('meta', property='og:title')[-1]['content']
822
        desc = soup.find_all('meta', property='og:description')[-1]['content']
823
        imgs = soup.find('div', id='comic').find_all('img')
824
        assert all(i['title'] == i['alt'] == title for i in imgs)
825
        return {
826
            'title': title,
827
            'description': desc,
828
            'img': [i['src'] for i in imgs],
829
        }
830
831
832
class ThreeWordPhrase(GenericNavigableComic):
833
    """Class to retrieve Three Word Phrase comics."""
834
    # Also on http://www.threewordphrase.tumblr.com
835
    name = 'threeword'
836
    long_name = 'Three Word Phrase'
837
    url = 'http://threewordphrase.com'
838
    get_url_from_link = join_cls_url_to_href
839
840
    @classmethod
841
    def get_first_comic_link(cls):
842
        """Get link to first comics."""
843
        return get_soup_at_url(cls.url).find('img', src='/firstlink.gif').parent
844
845
    @classmethod
846
    def get_navi_link(cls, last_soup, next_):
847
        """Get link to next or previous comic."""
848
        link = last_soup.find('img', src='/nextlink.gif' if next_ else '/prevlink.gif').parent
849
        return None if link.get('href') is None else link
850
851
    @classmethod
852
    def get_comic_info(cls, soup, link):
853
        """Get information about a particular comics."""
854
        title = soup.find('title')
855
        imgs = [img for img in soup.find_all('img')
856
                if not img['src'].endswith(
857
                    ('link.gif', '32.png', 'twpbookad.jpg',
858
                     'merchad.jpg', 'header.gif', 'tipjar.jpg'))]
859
        return {
860
            'title': title.string if title else None,
861
            'title2': '  '.join(img.get('alt') for img in imgs if img.get('alt')),
862
            'img': [urljoin_wrapper(cls.url, img['src']) for img in imgs],
863
        }
864
865
866
class DeadlyPanel(GenericEmptyComic, GenericNavigableComic):
867
    """Class to retrieve Deadly Panel comics."""
868
    # Also on https://tapastic.com/series/deadlypanel
869
    name = 'deadly'
870
    long_name = 'Deadly Panel'
871
    url = 'http://www.deadlypanel.com'
872
    get_first_comic_link = get_a_navi_navifirst
873
    get_navi_link = get_a_navi_comicnavnext_navinext
874
875
    @classmethod
876
    def get_comic_info(cls, soup, link):
877
        """Get information about a particular comics."""
878
        imgs = soup.find('div', id='comic').find_all('img')
879
        assert all(i['alt'] == i['title'] for i in imgs)
880
        return {
881
            'img': [i['src'] for i in imgs],
882
        }
883
884
885
class TheGentlemanArmchair(GenericNavigableComic):
886
    """Class to retrieve The Gentleman Armchair comics."""
887
    name = 'gentlemanarmchair'
888
    long_name = 'The Gentleman Armchair'
889
    url = 'http://thegentlemansarmchair.com'
890
    get_first_comic_link = get_a_navi_navifirst
891
    get_navi_link = get_link_rel_next
892
893
    @classmethod
894
    def get_comic_info(cls, soup, link):
895
        """Get information about a particular comics."""
896
        title = soup.find('h2', class_='post-title').string
897
        author = soup.find("span", class_="post-author").find("a").string
898
        date_str = soup.find('span', class_='post-date').string
899
        day = string_to_date(date_str, "%B %d, %Y")
900
        imgs = soup.find('div', id='comic').find_all('img')
901
        return {
902
            'img': [i['src'] for i in imgs],
903
            'title': title,
904
            'author': author,
905
            'month': day.month,
906
            'year': day.year,
907
            'day': day.day,
908
        }
909
910
911
class MyExtraLife(GenericNavigableComic):
912
    """Class to retrieve My Extra Life comics."""
913
    name = 'extralife'
914
    long_name = 'My Extra Life'
915
    url = 'http://www.myextralife.com'
916
    get_navi_link = get_link_rel_next
917
918
    @classmethod
919
    def get_first_comic_link(cls):
920
        """Get link to first comics."""
921
        return get_soup_at_url(cls.url).find('a', class_='comic_nav_link first_comic_link')
922
923
    @classmethod
924
    def get_comic_info(cls, soup, link):
925
        """Get information about a particular comics."""
926
        title = soup.find("h1", class_="comic_title").string
927
        date_str = soup.find("span", class_="comic_date").string
928
        day = string_to_date(date_str, "%B %d, %Y")
929
        imgs = soup.find_all("img", class_="comic")
930
        assert all(i['alt'] == i['title'] == title for i in imgs)
931
        return {
932
            'title': title,
933
            'img': [i['src'] for i in imgs if i["src"]],
934
            'day': day.day,
935
            'month': day.month,
936
            'year': day.year
937
        }
938
939
940
class SaturdayMorningBreakfastCereal(GenericNavigableComic):
941
    """Class to retrieve Saturday Morning Breakfast Cereal comics."""
942
    # Also on http://www.gocomics.com/saturday-morning-breakfast-cereal
943
    # Also on http://smbc-comics.tumblr.com
944
    name = 'smbc'
945
    long_name = 'Saturday Morning Breakfast Cereal'
946
    url = 'http://www.smbc-comics.com'
947
    _categories = ('SMBC', )
948
    get_navi_link = get_a_rel_next
949
950
    @classmethod
951
    def get_first_comic_link(cls):
952
        """Get link to first comics."""
953
        return get_soup_at_url(cls.url).find('a', rel='start')
954
955
    @classmethod
956
    def get_comic_info(cls, soup, link):
957
        """Get information about a particular comics."""
958
        image1 = soup.find('img', id='cc-comic')
959
        image_url1 = image1['src']
960
        aftercomic = soup.find('div', id='aftercomic')
961
        image_url2 = aftercomic.find('img')['src'] if aftercomic else ''
962
        imgs = [image_url1] + ([image_url2] if image_url2 else [])
963
        date_str = soup.find('div', class_='cc-publishtime').contents[0]
964
        day = string_to_date(date_str, "%B %d, %Y")
965
        return {
966
            'title': image1['title'],
967
            'img': [urljoin_wrapper(cls.url, i) for i in imgs],
968
            'day': day.day,
969
            'month': day.month,
970
            'year': day.year
971
        }
972
973
974
class PerryBibleFellowship(GenericListableComic):
975
    """Class to retrieve Perry Bible Fellowship comics."""
976
    name = 'pbf'
977
    long_name = 'Perry Bible Fellowship'
978
    url = 'http://pbfcomics.com'
979
    get_url_from_archive_element = join_cls_url_to_href
980
981
    @classmethod
982
    def get_archive_elements(cls):
983
        comic_link_re = re.compile('^/[0-9]*/$')
984
        return reversed(get_soup_at_url(cls.url).find_all('a', href=comic_link_re))
985
986
    @classmethod
987
    def get_comic_info(cls, soup, link):
988
        """Get information about a particular comics."""
989
        url = cls.get_url_from_archive_element(link)
990
        comic_img_re = re.compile('^/archive_b/PBF.*')
991
        name = link.string
992
        num = int(link['name'])
993
        href = link['href']
994
        assert href == '/%d/' % num
995
        imgs = soup.find_all('img', src=comic_img_re)
996
        assert len(imgs) == 1
997
        assert imgs[0]['alt'] == name
998
        return {
999
            'num': num,
1000
            'name': name,
1001
            'img': [urljoin_wrapper(url, i['src']) for i in imgs],
1002
            'prefix': '%d-' % num,
1003
        }
1004
1005
1006
class Mercworks(GenericNavigableComic):
1007
    """Class to retrieve Mercworks comics."""
1008
    # Also on http://mercworks.tumblr.com
1009
    name = 'mercworks'
1010
    long_name = 'Mercworks'
1011
    url = 'http://mercworks.net'
1012
    get_first_comic_link = get_a_comicnavbase_comicnavfirst
1013
    get_navi_link = get_a_rel_next
1014
1015
    @classmethod
1016
    def get_comic_info(cls, soup, link):
1017
        """Get information about a particular comics."""
1018
        title = soup.find('meta', property='og:title')['content']
1019
        metadesc = soup.find('meta', property='og:description')
1020
        desc = metadesc['content'] if metadesc else ""
1021
        author = soup.find('meta', attrs={'name': 'shareaholic:article_author_name'})['content']
1022
        date_str = soup.find('meta', attrs={'name': 'shareaholic:article_published_time'})['content']
1023
        date_str = date_str[:10]
1024
        day = string_to_date(date_str, "%Y-%m-%d")
1025
        imgs = soup.find_all('meta', property='og:image')
1026
        return {
1027
            'img': [i['content'] for i in imgs],
1028
            'title': title,
1029
            'author': author,
1030
            'desc': desc,
1031
            'day': day.day,
1032
            'month': day.month,
1033
            'year': day.year
1034
        }
1035
1036
1037
class BerkeleyMews(GenericListableComic):
1038
    """Class to retrieve Berkeley Mews comics."""
1039
    # Also on http://mews.tumblr.com
1040
    # Also on http://www.gocomics.com/berkeley-mews
1041
    name = 'berkeley'
1042
    long_name = 'Berkeley Mews'
1043
    url = 'http://www.berkeleymews.com'
1044
    _categories = ('BERKELEY', )
1045
    get_url_from_archive_element = get_href
1046
    comic_num_re = re.compile('%s/\\?p=([0-9]*)$' % url)
1047
1048
    @classmethod
1049
    def get_archive_elements(cls):
1050
        archive_url = urljoin_wrapper(cls.url, "?page_id=2")
1051
        return reversed(get_soup_at_url(archive_url).find_all('a', href=cls.comic_num_re))
1052
1053
    @classmethod
1054
    def get_comic_info(cls, soup, link):
1055
        """Get information about a particular comics."""
1056
        comic_date_re = re.compile('.*/([0-9]*)-([0-9]*)-([0-9]*)-.*')
1057
        url = cls.get_url_from_archive_element(link)
1058
        num = int(cls.comic_num_re.match(url).groups()[0])
1059
        img = soup.find('div', id='comic').find('img')
1060
        assert all(i['alt'] == i['title'] for i in [img])
1061
        title2 = img['title']
1062
        img_url = img['src']
1063
        year, month, day = [int(s) for s in comic_date_re.match(img_url).groups()]
1064
        return {
1065
            'num': num,
1066
            'title': link.string,
1067
            'title2': title2,
1068
            'img': [img_url],
1069
            'year': year,
1070
            'month': month,
1071
            'day': day,
1072
        }
1073
1074
1075
class GenericBouletCorp(GenericNavigableComic):
1076
    """Generic class to retrieve BouletCorp comics in different languages."""
1077
    # Also on http://bouletcorp.tumblr.com
1078
    _categories = ('BOULET', )
1079
    get_navi_link = get_link_rel_next
1080
1081
    @classmethod
1082
    def get_first_comic_link(cls):
1083
        """Get link to first comics."""
1084
        return get_soup_at_url(cls.url).find('div', id='centered_nav').find_all('a')[0]
1085
1086
    @classmethod
1087
    def get_comic_info(cls, soup, link):
1088
        """Get information about a particular comics."""
1089
        url = cls.get_url_from_link(link)
1090
        date_re = re.compile('^%s/([0-9]*)/([0-9]*)/([0-9]*)/' % cls.url)
1091
        year, month, day = [int(s) for s in date_re.match(url).groups()]
1092
        imgs = soup.find('div', id='notes').find('div', class_='storycontent').find_all('img')
1093
        texts = '  '.join(t for t in (i.get('title') for i in imgs) if t)
1094
        title = soup.find('title').string
1095
        return {
1096
            'img': [convert_iri_to_plain_ascii_uri(i['src']) for i in imgs if i.get('src') is not None],
1097
            'title': title,
1098
            'texts': texts,
1099
            'year': year,
1100
            'month': month,
1101
            'day': day,
1102
        }
1103
1104
1105
class BouletCorp(GenericBouletCorp):
1106
    """Class to retrieve BouletCorp comics."""
1107
    name = 'boulet'
1108
    long_name = 'Boulet Corp'
1109
    url = 'http://www.bouletcorp.com'
1110
    _categories = ('FRANCAIS', )
1111
1112
1113
class BouletCorpEn(GenericBouletCorp):
1114
    """Class to retrieve EnglishBouletCorp comics."""
1115
    name = 'boulet_en'
1116
    long_name = 'Boulet Corp English'
1117
    url = 'http://english.bouletcorp.com'
1118
1119
1120
class AmazingSuperPowers(GenericNavigableComic):
1121
    """Class to retrieve Amazing Super Powers comics."""
1122
    name = 'asp'
1123
    long_name = 'Amazing Super Powers'
1124
    url = 'http://www.amazingsuperpowers.com'
1125
    get_first_comic_link = get_a_navi_navifirst
1126
    get_navi_link = get_a_navi_navinext
1127
1128
    @classmethod
1129
    def get_comic_info(cls, soup, link):
1130
        """Get information about a particular comics."""
1131
        author = soup.find("span", class_="post-author").find("a").string
1132
        date_str = soup.find('span', class_='post-date').string
1133
        day = string_to_date(date_str, "%B %d, %Y")
1134
        imgs = soup.find('div', id='comic').find_all('img')
1135
        title = ' '.join(i['title'] for i in imgs)
1136
        assert all(i['alt'] == i['title'] for i in imgs)
1137
        return {
1138
            'title': title,
1139
            'author': author,
1140
            'img': [img['src'] for img in imgs],
1141
            'day': day.day,
1142
            'month': day.month,
1143
            'year': day.year
1144
        }
1145
1146
1147
class ToonHole(GenericNavigableComic):
1148
    """Class to retrieve Toon Holes comics."""
1149
    # Also on http://tapastic.com/series/TOONHOLE
1150
    name = 'toonhole'
1151
    long_name = 'Toon Hole'
1152
    url = 'http://www.toonhole.com'
1153
    get_first_comic_link = get_a_comicnavbase_comicnavfirst
1154
    get_navi_link = get_link_rel_next
1155
1156
    @classmethod
1157
    def get_comic_info(cls, soup, link):
1158
        """Get information about a particular comics."""
1159
        short_url = soup.find('link', rel='shortlink')['href']
1160
        date_str = soup.find('time', class_='entry-date published').string
1161
        day = string_to_date(date_str, "%B %d, %Y")
1162
        imgs = soup.find('div', id='comic').find_all('img')
1163
        if imgs:
1164
            img = imgs[0]
1165
            title = img['alt']
1166
            assert img['title'] == title
1167
        else:
1168
            title = ""
1169
        return {
1170
            'short_url': short_url,
1171
            'title': title,
1172
            'month': day.month,
1173
            'year': day.year,
1174
            'day': day.day,
1175
            'img': [convert_iri_to_plain_ascii_uri(i['src']) for i in imgs],
1176
        }
1177
1178
1179
class Channelate(GenericNavigableComic):
1180
    """Class to retrieve Channelate comics."""
1181
    name = 'channelate'
1182
    long_name = 'Channelate'
1183
    url = 'http://www.channelate.com'
1184
    get_first_comic_link = get_div_navfirst_a
1185
    get_navi_link = get_link_rel_next
1186
    get_url_from_link = join_cls_url_to_href
1187
1188
    @classmethod
1189
    def get_comic_info(cls, soup, link):
1190
        """Get information about a particular comics."""
1191
        author = soup.find("span", class_="post-author").find("a").string
1192
        date_str = soup.find('span', class_='post-date').string
1193
        day = string_to_date(date_str, '%Y/%m/%d')
1194
        title = soup.find('meta', property='og:title')['content']
1195
        post = soup.find('div', id='comic')
1196
        imgs = post.find_all('img') if post else []
1197
        extra_url = None
1198
        extra_div = soup.find('div', id='extrapanelbutton')
1199
        if extra_div:
1200
            extra_url = extra_div.find('a')['href']
1201
            extra_soup = get_soup_at_url(extra_url)
1202
            extra_imgs = extra_soup.find_all('img', class_='extrapanelimage')
1203
            imgs.extend(extra_imgs)
1204
        return {
1205
            'url_extra': extra_url,
1206
            'title': title,
1207
            'author': author,
1208
            'month': day.month,
1209
            'year': day.year,
1210
            'day': day.day,
1211
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
1212
        }
1213
1214
1215
class CyanideAndHappiness(GenericNavigableComic):
1216
    """Class to retrieve Cyanide And Happiness comics."""
1217
    name = 'cyanide'
1218
    long_name = 'Cyanide and Happiness'
1219
    url = 'http://explosm.net'
1220
    _categories = ('NSFW', )
1221
    get_url_from_link = join_cls_url_to_href
1222
1223
    @classmethod
1224
    def get_first_comic_link(cls):
1225
        """Get link to first comics."""
1226
        return get_soup_at_url(cls.url).find('a', title='Oldest comic')
1227
1228
    @classmethod
1229
    def get_navi_link(cls, last_soup, next_):
1230
        """Get link to next or previous comic."""
1231
        link = last_soup.find('a', class_='next-comic' if next_ else 'previous-comic ')
1232
        return None if link.get('href') is None else link
1233
1234
    @classmethod
1235
    def get_comic_info(cls, soup, link):
1236
        """Get information about a particular comics."""
1237
        url2 = soup.find('meta', property='og:url')['content']
1238
        num = int(url2.split('/')[-2])
1239
        date_str = soup.find('h3').find('a').string
1240
        day = string_to_date(date_str, '%Y.%m.%d')
1241
        author = soup.find('small', class_="author-credit-name").string
1242
        assert author.startswith('by ')
1243
        author = author[3:]
1244
        imgs = soup.find_all('img', id='main-comic')
1245
        return {
1246
            'num': num,
1247
            'author': author,
1248
            'month': day.month,
1249
            'year': day.year,
1250
            'day': day.day,
1251
            'prefix': '%d-' % num,
1252
            'img': [convert_iri_to_plain_ascii_uri(urljoin_wrapper(cls.url, i['src'])) for i in imgs]
1253
        }
1254
1255
1256
class MrLovenstein(GenericComic):
1257
    """Class to retrieve Mr Lovenstein comics."""
1258
    # Also on https://tapastic.com/series/MrLovenstein
1259
    name = 'mrlovenstein'
1260
    long_name = 'Mr. Lovenstein'
1261
    url = 'http://www.mrlovenstein.com'
1262
1263
    @classmethod
1264
    def get_next_comic(cls, last_comic):
1265
        """Generator to get the next comic. Implementation of GenericComic's abstract method."""
1266
        # TODO: more info from http://www.mrlovenstein.com/archive
1267
        comic_num_re = re.compile('^/comic/([0-9]*)$')
1268
        nums = [int(comic_num_re.match(link['href']).groups()[0])
1269
                for link in get_soup_at_url(cls.url).find_all('a', href=comic_num_re)]
1270
        first, last = min(nums), max(nums)
1271
        if last_comic:
1272
            first = last_comic['num'] + 1
1273
        for num in range(first, last + 1):
1274
            url = urljoin_wrapper(cls.url, '/comic/%d' % num)
1275
            soup = get_soup_at_url(url)
1276
            imgs = list(
1277
                reversed(soup.find_all('img', src=re.compile('^/images/comics/'))))
1278
            description = soup.find('meta', attrs={'name': 'description'})['content']
1279
            yield {
1280
                'url': url,
1281
                'num': num,
1282
                'texts': '  '.join(t for t in (i.get('title') for i in imgs) if t),
1283
                'img': [urljoin_wrapper(url, i['src']) for i in imgs],
1284
                'description': description,
1285
            }
1286
1287
1288
class DinosaurComics(GenericListableComic):
1289
    """Class to retrieve Dinosaur Comics comics."""
1290
    name = 'dinosaur'
1291
    long_name = 'Dinosaur Comics'
1292
    url = 'http://www.qwantz.com'
1293
    get_url_from_archive_element = get_href
1294
    comic_link_re = re.compile('^%s/index.php\\?comic=([0-9]*)$' % url)
1295
1296
    @classmethod
1297
    def get_archive_elements(cls):
1298
        archive_url = urljoin_wrapper(cls.url, 'archive.php')
1299
        # first link is random -> skip it
1300
        return reversed(get_soup_at_url(archive_url).find_all('a', href=cls.comic_link_re)[1:])
1301
1302
    @classmethod
1303
    def get_comic_info(cls, soup, link):
1304
        """Get information about a particular comics."""
1305
        url = cls.get_url_from_archive_element(link)
1306
        num = int(cls.comic_link_re.match(url).groups()[0])
1307
        date_str = link.string
1308
        text = link.next_sibling.string
1309
        day = string_to_date(remove_st_nd_rd_th_from_date(date_str), "%B %d, %Y")
1310
        comic_img_re = re.compile('^%s/comics/' % cls.url)
1311
        img = soup.find('img', src=comic_img_re)
1312
        return {
1313
            'month': day.month,
1314
            'year': day.year,
1315
            'day': day.day,
1316
            'img': [img.get('src')],
1317
            'title': img.get('title'),
1318
            'text': text,
1319
            'num': num,
1320
        }
1321
1322
1323
class ButterSafe(GenericListableComic):
1324
    """Class to retrieve Butter Safe comics."""
1325
    name = 'butter'
1326
    long_name = 'ButterSafe'
1327 View Code Duplication
    url = 'http://buttersafe.com'
1328
    get_url_from_archive_element = get_href
1329
    comic_link_re = re.compile('^%s/([0-9]*)/([0-9]*)/([0-9]*)/.*' % url)
1330
1331
    @classmethod
1332
    def get_archive_elements(cls):
1333
        archive_url = urljoin_wrapper(cls.url, 'archive/')
1334
        return reversed(get_soup_at_url(archive_url).find_all('a', href=cls.comic_link_re))
1335
1336
    @classmethod
1337
    def get_comic_info(cls, soup, link):
1338
        """Get information about a particular comics."""
1339
        url = cls.get_url_from_archive_element(link)
1340
        title = link.string
1341
        year, month, day = [int(s) for s in cls.comic_link_re.match(url).groups()]
1342
        img = soup.find('div', id='comic').find('img')
1343
        assert img['alt'] == title
1344
        return {
1345
            'title': title,
1346
            'day': day,
1347
            'month': month,
1348
            'year': year,
1349
            'img': [img['src']],
1350
        }
1351
1352
1353
class CalvinAndHobbes(GenericComic):
1354
    """Class to retrieve Calvin and Hobbes comics."""
1355
    # Also on http://www.gocomics.com/calvinandhobbes/
1356
    name = 'calvin'
1357
    long_name = 'Calvin and Hobbes'
1358
    # This is not through any official webpage but eh...
1359
    url = 'http://marcel-oehler.marcellosendos.ch/comics/ch/'
1360
1361
    @classmethod
1362
    def get_next_comic(cls, last_comic):
1363
        """Generator to get the next comic. Implementation of GenericComic's abstract method."""
1364
        last_date = get_date_for_comic(
1365
            last_comic) if last_comic else date(1985, 11, 1)
1366
        link_re = re.compile('^([0-9]*)/([0-9]*)/')
1367
        img_re = re.compile('')
1368
        for link in get_soup_at_url(cls.url).find_all('a', href=link_re):
1369
            url = link['href']
1370
            year, month = link_re.match(url).groups()
1371
            if date(int(year), int(month), 1) + timedelta(days=31) >= last_date:
1372
                img_re = re.compile('^%s%s([0-9]*)' % (year, month))
1373
                month_url = urljoin_wrapper(cls.url, url)
1374
                for img in get_soup_at_url(month_url).find_all('img', src=img_re):
1375
                    img_src = img['src']
1376
                    day = int(img_re.match(img_src).groups()[0])
1377
                    comic_date = date(int(year), int(month), day)
1378
                    if comic_date > last_date:
1379
                        yield {
1380
                            'url': month_url,
1381
                            'year': int(year),
1382
                            'month': int(month),
1383
                            'day': int(day),
1384
                            'img': ['%s%s/%s/%s' % (cls.url, year, month, img_src)],
1385
                        }
1386
                        last_date = comic_date
1387
1388
1389
class AbstruseGoose(GenericListableComic):
1390
    """Class to retrieve AbstruseGoose Comics."""
1391
    name = 'abstruse'
1392
    long_name = 'Abstruse Goose'
1393 View Code Duplication
    url = 'http://abstrusegoose.com'
1394
    get_url_from_archive_element = get_href
1395
    comic_url_re = re.compile('^%s/([0-9]*)$' % url)
1396
    comic_img_re = re.compile('^%s/strips/.*' % url)
1397
1398
    @classmethod
1399
    def get_archive_elements(cls):
1400
        archive_url = urljoin_wrapper(cls.url, 'archive')
1401
        return get_soup_at_url(archive_url).find_all('a', href=cls.comic_url_re)
1402
1403
    @classmethod
1404
    def get_comic_info(cls, soup, archive_elt):
1405
        comic_url = cls.get_url_from_archive_element(archive_elt)
1406
        num = int(cls.comic_url_re.match(comic_url).groups()[0])
1407
        return {
1408
            'num': num,
1409
            'title': archive_elt.string,
1410
            'img': [soup.find('img', src=cls.comic_img_re)['src']]
1411
        }
1412
1413
1414
class PhDComics(GenericNavigableComic):
1415
    """Class to retrieve PHD Comics."""
1416
    name = 'phd'
1417
    long_name = 'PhD Comics'
1418
    url = 'http://phdcomics.com/comics/archive.php'
1419
    get_url_from_link = join_cls_url_to_href
1420
1421
    @classmethod
1422
    def get_first_comic_link(cls):
1423
        """Get link to first comics."""
1424
        return get_soup_at_url(cls.url).find('img', src='images/first_button.gif').parent
1425
1426
    @classmethod
1427
    def get_navi_link(cls, last_soup, next_):
1428
        """Get link to next or previous comic."""
1429
        img = last_soup.find('img', src='images/next_button.gif' if next_ else 'images/prev_button.gif')
1430
        return None if img is None else img.parent
1431
1432
    @classmethod
1433 View Code Duplication
    def get_comic_info(cls, soup, link):
1434
        """Get information about a particular comics."""
1435
        date_str = soup.find('font', face='Arial,Helvetica,Geneva,Swiss,SunSans-Regular', color='white').string.strip()
1436
        try:
1437
            day = string_to_date(date_str, '%m/%d/%Y')
1438
        except ValueError:
1439
            print("Invalid date %s" % date_str)
1440
            day = date.today()
1441
        title = soup.find('meta', attrs={'name': 'twitter:title'})['content']
1442
        return {
1443
            'year': day.year,
1444
            'month': day.month,
1445
            'day': day.day,
1446
            'img': [soup.find('img', id='comic')['src']],
1447
            'title': title,
1448
        }
1449
1450
1451
class Octopuns(GenericEmptyComic, GenericNavigableComic):
1452
    """Class to retrieve Octopuns comics."""
1453
    # Also on http://octopuns.tumblr.com
1454
    name = 'octopuns'
1455
    long_name = 'Octopuns'
1456
    url = 'http://www.octopuns.net'
1457
1458
    @classmethod
1459
    def get_first_comic_link(cls):
1460
        """Get link to first comics."""
1461
        return get_soup_at_url(cls.url).find('img', src=re.compile('.*/First.png')).parent
1462
1463
    @classmethod
1464
    def get_navi_link(cls, last_soup, next_):
1465
        """Get link to next or previous comic."""
1466
        link = last_soup.find('img', src=re.compile('.*/Next.png' if next_ else '.*/Back.png')).parent
1467
        return None if link.get('href') is None else link
1468
1469
    @classmethod
1470
    def get_comic_info(cls, soup, link):
1471
        """Get information about a particular comics."""
1472
        title = soup.find('h3', class_='post-title entry-title').string
1473
        date_str = soup.find('h2', class_='date-header').string
1474
        day = string_to_date(date_str, "%A, %B %d, %Y")
1475
        imgs = soup.find_all('link', rel='image_src')
1476
        return {
1477
            'img': [i['href'] for i in imgs],
1478
            'title': title,
1479
            'day': day.day,
1480
            'month': day.month,
1481
            'year': day.year,
1482
        }
1483
1484
1485
class Quarktees(GenericNavigableComic):
1486
    """Class to retrieve the Quarktees comics."""
1487
    name = 'quarktees'
1488
    long_name = 'Quarktees'
1489
    url = 'http://www.quarktees.com/blogs/news'
1490
    get_url_from_link = join_cls_url_to_href
1491
    get_first_comic_link = simulate_first_link
1492
    first_url = 'http://www.quarktees.com/blogs/news/12486621-coming-soon'
1493
1494
    @classmethod
1495
    def get_navi_link(cls, last_soup, next_):
1496
        """Get link to next or previous comic."""
1497
        return last_soup.find('a', id='article-next' if next_ else 'article-prev')
1498
1499
    @classmethod
1500
    def get_comic_info(cls, soup, link):
1501
        """Get information about a particular comics."""
1502
        title = soup.find('meta', property='og:title')['content']
1503
        article = soup.find('div', class_='single-article')
1504
        imgs = article.find_all('img')
1505
        return {
1506
            'title': title,
1507
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
1508
        }
1509
1510
1511
class OverCompensating(GenericNavigableComic):
1512
    """Class to retrieve the Over Compensating comics."""
1513
    name = 'compensating'
1514
    long_name = 'Over Compensating'
1515
    url = 'http://www.overcompensating.com'
1516
    get_url_from_link = join_cls_url_to_href
1517
1518
    @classmethod
1519
    def get_first_comic_link(cls):
1520
        """Get link to first comics."""
1521
        return get_soup_at_url(cls.url).find('a', href=re.compile('comic=1$'))
1522
1523
    @classmethod
1524
    def get_navi_link(cls, last_soup, next_):
1525
        """Get link to next or previous comic."""
1526
        return last_soup.find('a', title='next comic' if next_ else 'go back already')
1527
1528
    @classmethod
1529
    def get_comic_info(cls, soup, link):
1530
        """Get information about a particular comics."""
1531
        img_src_re = re.compile('^/oc/comics/.*')
1532
        comic_num_re = re.compile('.*comic=([0-9]*)$')
1533
        comic_url = cls.get_url_from_link(link)
1534
        num = int(comic_num_re.match(comic_url).groups()[0])
1535
        img = soup.find('img', src=img_src_re)
1536
        return {
1537
            'num': num,
1538
            'img': [urljoin_wrapper(comic_url, img['src'])],
1539
            'title': img.get('title')
1540
        }
1541
1542
1543
class Oglaf(GenericNavigableComic):
1544
    """Class to retrieve Oglaf comics."""
1545
    name = 'oglaf'
1546
    long_name = 'Oglaf [NSFW]'
1547
    url = 'http://oglaf.com'
1548
    _categories = ('NSFW', )
1549
    get_url_from_link = join_cls_url_to_href
1550
1551
    @classmethod
1552
    def get_first_comic_link(cls):
1553
        """Get link to first comics."""
1554
        return get_soup_at_url(cls.url).find("div", id="st").parent
1555
1556
    @classmethod
1557
    def get_navi_link(cls, last_soup, next_):
1558
        """Get link to next or previous comic."""
1559
        div = last_soup.find("div", id="nx" if next_ else "pvs")
1560
        return div.parent if div else None
1561
1562
    @classmethod
1563
    def get_comic_info(cls, soup, link):
1564
        """Get information about a particular comics."""
1565
        title = soup.find('title').string
1566
        title_imgs = soup.find('div', id='tt').find_all('img')
1567
        assert len(title_imgs) == 1
1568
        strip_imgs = soup.find_all('img', id='strip')
1569
        assert len(strip_imgs) == 1
1570
        imgs = title_imgs + strip_imgs
1571
        desc = ' '.join(i['title'] for i in imgs)
1572
        return {
1573
            'title': title,
1574
            'img': [i['src'] for i in imgs],
1575
            'description': desc,
1576
        }
1577
1578
1579
class ScandinaviaAndTheWorld(GenericNavigableComic):
1580
    """Class to retrieve Scandinavia And The World comics."""
1581
    name = 'satw'
1582
    long_name = 'Scandinavia And The World'
1583
    url = 'http://satwcomic.com'
1584
    get_first_comic_link = simulate_first_link
1585
    first_url = 'http://satwcomic.com/sweden-denmark-and-norway'
1586
1587
    @classmethod
1588
    def get_navi_link(cls, last_soup, next_):
1589
        """Get link to next or previous comic."""
1590
        return last_soup.find('a', accesskey='n' if next_ else 'p')
1591
1592
    @classmethod
1593
    def get_comic_info(cls, soup, link):
1594
        """Get information about a particular comics."""
1595
        title = soup.find('meta', attrs={'name': 'twitter:label1'})['content']
1596
        desc = soup.find('meta', property='og:description')['content']
1597
        imgs = soup.find_all('img', itemprop="image")
1598
        return {
1599
            'title': title,
1600
            'description': desc,
1601
            'img': [i['src'] for i in imgs],
1602
        }
1603
1604
1605
class SomethingOfThatIlk(GenericEmptyComic):  # Does not exist anymore
1606
    """Class to retrieve the Something Of That Ilk comics."""
1607
    name = 'somethingofthatilk'
1608
    long_name = 'Something Of That Ilk'
1609
    url = 'http://www.somethingofthatilk.com'
1610
1611
1612
class InfiniteMonkeyBusiness(GenericNavigableComic):
1613
    """Generic class to retrieve InfiniteMonkeyBusiness comics."""
1614
    name = 'monkey'
1615
    long_name = 'Infinite Monkey Business'
1616
    url = 'http://infinitemonkeybusiness.net'
1617
    get_navi_link = get_a_navi_comicnavnext_navinext
1618
    get_first_comic_link = simulate_first_link
1619
    first_url = 'http://infinitemonkeybusiness.net/comic/pillory/'
1620
1621
    @classmethod
1622
    def get_comic_info(cls, soup, link):
1623
        """Get information about a particular comics."""
1624
        title = soup.find('meta', property='og:title')['content']
1625
        imgs = soup.find('div', id='comic').find_all('img')
1626
        return {
1627
            'title': title,
1628
            'img': [i['src'] for i in imgs],
1629
        }
1630
1631
1632
class Wondermark(GenericListableComic):
1633
    """Class to retrieve the Wondermark comics."""
1634
    name = 'wondermark'
1635
    long_name = 'Wondermark'
1636
    url = 'http://wondermark.com'
1637
    get_url_from_archive_element = get_href
1638
1639
    @classmethod
1640
    def get_archive_elements(cls):
1641
        archive_url = urljoin_wrapper(cls.url, 'archive/')
1642
        return reversed(get_soup_at_url(archive_url).find_all('a', rel='bookmark'))
1643
1644
    @classmethod
1645
    def get_comic_info(cls, soup, link):
1646
        """Get information about a particular comics."""
1647
        date_str = soup.find('div', class_='postdate').find('em').string
1648
        day = string_to_date(remove_st_nd_rd_th_from_date(date_str), "%B %d, %Y")
1649
        div = soup.find('div', id='comic')
1650 View Code Duplication
        if div:
1651
            img = div.find('img')
1652
            img_src = [img['src']]
1653
            alt = img['alt']
1654
            assert alt == img['title']
1655
            title = soup.find('meta', property='og:title')['content']
1656
        else:
1657
            img_src = []
1658
            alt = ''
1659
            title = ''
1660
        return {
1661
            'month': day.month,
1662
            'year': day.year,
1663
            'day': day.day,
1664
            'img': img_src,
1665
            'title': title,
1666
            'alt': alt,
1667
            'tags': ' '.join(t.string for t in soup.find('div', class_='postmeta').find_all('a', rel='tag')),
1668
        }
1669
1670
1671
class WarehouseComic(GenericNavigableComic):
1672
    """Class to retrieve Warehouse Comic comics."""
1673
    name = 'warehouse'
1674
    long_name = 'Warehouse Comic'
1675
    url = 'http://warehousecomic.com'
1676
    get_first_comic_link = get_a_navi_navifirst
1677
    get_navi_link = get_link_rel_next
1678
1679
    @classmethod
1680
    def get_comic_info(cls, soup, link):
1681
        """Get information about a particular comics."""
1682
        title = soup.find('h2', class_='post-title').string
1683
        date_str = soup.find('span', class_='post-date').string
1684
        day = string_to_date(date_str, "%B %d, %Y")
1685
        imgs = soup.find('div', id='comic').find_all('img')
1686
        return {
1687
            'img': [i['src'] for i in imgs],
1688
            'title': title,
1689
            'day': day.day,
1690
            'month': day.month,
1691
            'year': day.year,
1692
        }
1693
1694
1695
class JustSayEh(GenericNavigableComic):
1696
    """Class to retrieve Just Say Eh comics."""
1697
    # Also on http//tapastic.com/series/Just-Say-Eh
1698
    name = 'justsayeh'
1699
    long_name = 'Just Say Eh'
1700
    url = 'http://www.justsayeh.com'
1701
    get_first_comic_link = get_a_navi_navifirst
1702
    get_navi_link = get_a_navi_comicnavnext_navinext
1703
1704
    @classmethod
1705
    def get_comic_info(cls, soup, link):
1706
        """Get information about a particular comics."""
1707
        title = soup.find('h2', class_='post-title').string
1708
        imgs = soup.find("div", id="comic").find_all("img")
1709
        assert all(i['alt'] == i['title'] for i in imgs)
1710
        alt = imgs[0]['alt']
1711
        return {
1712
            'img': [i['src'] for i in imgs],
1713
            'title': title,
1714
            'alt': alt,
1715
        }
1716
1717
1718
class MouseBearComedy(GenericNavigableComic):
1719
    """Class to retrieve Mouse Bear Comedy comics."""
1720
    # Also on http://mousebearcomedy.tumblr.com
1721
    name = 'mousebear'
1722
    long_name = 'Mouse Bear Comedy'
1723
    url = 'http://www.mousebearcomedy.com'
1724
    get_first_comic_link = get_a_navi_navifirst
1725
    get_navi_link = get_a_navi_comicnavnext_navinext
1726
1727
    @classmethod
1728
    def get_comic_info(cls, soup, link):
1729
        """Get information about a particular comics."""
1730
        title = soup.find('h2', class_='post-title').string
1731
        author = soup.find("span", class_="post-author").find("a").string
1732
        date_str = soup.find("span", class_="post-date").string
1733
        day = string_to_date(date_str, '%B %d, %Y')
1734
        imgs = soup.find("div", id="comic").find_all("img")
1735
        assert all(i['alt'] == i['title'] == title for i in imgs)
1736
        return {
1737
            'day': day.day,
1738
            'month': day.month,
1739
            'year': day.year,
1740
            'img': [i['src'] for i in imgs],
1741
            'title': title,
1742
            'author': author,
1743
        }
1744 View Code Duplication
1745
1746
class BigFootJustice(GenericNavigableComic):
1747
    """Class to retrieve Big Foot Justice comics."""
1748
    # Also on http://tapastic.com/series/bigfoot-justice
1749
    name = 'bigfoot'
1750
    long_name = 'Big Foot Justice'
1751
    url = 'http://bigfootjustice.com'
1752
    get_first_comic_link = get_a_navi_navifirst
1753
    get_navi_link = get_a_navi_comicnavnext_navinext
1754
1755
    @classmethod
1756
    def get_comic_info(cls, soup, link):
1757
        """Get information about a particular comics."""
1758
        imgs = soup.find('div', id='comic').find_all('img')
1759
        assert all(i['title'] == i['alt'] for i in imgs)
1760
        title = ' '.join(i['title'] for i in imgs)
1761
        return {
1762
            'img': [i['src'] for i in imgs],
1763
            'title': title,
1764
        }
1765
1766
1767
class RespawnComic(GenericNavigableComic):
1768
    """Class to retrieve Respawn Comic."""
1769
    # Also on http://respawncomic.tumblr.com
1770
    name = 'respawn'
1771
    long_name = 'Respawn Comic'
1772
    url = 'http://respawncomic.com '
1773
    _categories = ('RESPAWN', )
1774
    get_navi_link = get_a_rel_next
1775
    get_first_comic_link = simulate_first_link
1776
    first_url = 'http://respawncomic.com/comic/c0001/'
1777
1778
    @classmethod
1779
    def get_comic_info(cls, soup, link):
1780
        """Get information about a particular comics."""
1781 View Code Duplication
        title = soup.find('meta', property='og:title')['content']
1782
        author = soup.find('meta', attrs={'name': 'shareaholic:article_author_name'})['content']
1783
        date_str = soup.find('meta', attrs={'name': 'shareaholic:article_published_time'})['content']
1784
        date_str = date_str[:10]
1785
        day = string_to_date(date_str, "%Y-%m-%d")
1786
        imgs = soup.find_all('meta', property='og:image')
1787
        skip_imgs = {
1788
            'http://respawncomic.com/wp-content/uploads/2016/03/site/HAROLD2.png',
1789
            'http://respawncomic.com/wp-content/uploads/2016/03/site/DEVA.png'
1790
        }
1791
        return {
1792
            'title': title,
1793
            'author': author,
1794
            'day': day.day,
1795
            'month': day.month,
1796
            'year': day.year,
1797
            'img': [i['content'] for i in imgs if i['content'] not in skip_imgs],
1798
        }
1799
1800
1801
class SafelyEndangered(GenericNavigableComic):
1802
    """Class to retrieve Safely Endangered comics."""
1803
    # Also on http://tumblr.safelyendangered.com
1804
    name = 'endangered'
1805
    long_name = 'Safely Endangered'
1806
    url = 'http://www.safelyendangered.com'
1807
    get_navi_link = get_link_rel_next
1808
    get_first_comic_link = simulate_first_link
1809
    first_url = 'http://www.safelyendangered.com/comic/ignored/'
1810 View Code Duplication
1811
    @classmethod
1812
    def get_comic_info(cls, soup, link):
1813
        """Get information about a particular comics."""
1814
        title = soup.find('h2', class_='post-title').string
1815
        date_str = soup.find('span', class_='post-date').string
1816
        day = string_to_date(date_str, '%B %d, %Y')
1817
        imgs = soup.find('div', id='comic').find_all('img')
1818
        alt = imgs[0]['alt']
1819
        assert all(i['alt'] == i['title'] for i in imgs)
1820
        return {
1821
            'day': day.day,
1822
            'month': day.month,
1823
            'year': day.year,
1824
            'img': [i['src'] for i in imgs],
1825
            'title': title,
1826
            'alt': alt,
1827
        }
1828
1829
1830
class PicturesInBoxes(GenericNavigableComic):
1831
    """Class to retrieve Pictures In Boxes comics."""
1832
    # Also on http://picturesinboxescomic.tumblr.com
1833
    name = 'picturesinboxes'
1834
    long_name = 'Pictures in Boxes'
1835
    url = 'http://www.picturesinboxes.com'
1836
    get_navi_link = get_a_navi_navinext
1837
    get_first_comic_link = simulate_first_link
1838
    first_url = 'http://www.picturesinboxes.com/2013/10/26/tetris/'
1839
1840
    @classmethod
1841
    def get_comic_info(cls, soup, link):
1842
        """Get information about a particular comics."""
1843
        title = soup.find('h2', class_='post-title').string
1844
        author = soup.find("span", class_="post-author").find("a").string
1845
        date_str = soup.find('span', class_='post-date').string
1846
        day = string_to_date(date_str, '%B %d, %Y')
1847
        imgs = soup.find('div', class_='comicpane').find_all('img')
1848
        assert imgs
1849
        assert all(i['title'] == i['alt'] == title for i in imgs)
1850
        return {
1851
            'day': day.day,
1852
            'month': day.month,
1853
            'year': day.year,
1854
            'img': [i['src'] for i in imgs],
1855
            'title': title,
1856
            'author': author,
1857
        }
1858
1859
1860
class Penmen(GenericEmptyComic):
1861
    """Class to retrieve Penmen comics."""
1862
    name = 'penmen'
1863
    long_name = 'Penmen'
1864
    url = 'http://penmen.com'
1865
1866
1867
class TheDoghouseDiaries(GenericNavigableComic):
1868
    """Class to retrieve The Dog House Diaries comics."""
1869
    name = 'doghouse'
1870
    long_name = 'The Dog House Diaries'
1871
    url = 'http://thedoghousediaries.com'
1872
1873
    @classmethod
1874
    def get_first_comic_link(cls):
1875
        """Get link to first comics."""
1876
        return get_soup_at_url(cls.url).find('a', id='firstlink')
1877
1878
    @classmethod
1879
    def get_navi_link(cls, last_soup, next_):
1880
        """Get link to next or previous comic."""
1881
        return last_soup.find('a', id='nextlink' if next_ else 'previouslink')
1882
1883
    @classmethod
1884
    def get_comic_info(cls, soup, link):
1885
        """Get information about a particular comics."""
1886
        comic_img_re = re.compile('^dhdcomics/.*')
1887
        img = soup.find('img', src=comic_img_re)
1888
        comic_url = cls.get_url_from_link(link)
1889
        return {
1890
            'title': soup.find('h2', id='titleheader').string,
1891
            'title2': soup.find('div', id='subtext').string,
1892
            'alt': img.get('title'),
1893
            'img': [urljoin_wrapper(comic_url, img['src'].strip())],
1894
            'num': int(comic_url.split('/')[-1]),
1895
        }
1896
1897
1898
class InvisibleBread(GenericListableComic):
1899
    """Class to retrieve Invisible Bread comics."""
1900
    # Also on http://www.gocomics.com/invisible-bread
1901
    name = 'invisiblebread'
1902
    long_name = 'Invisible Bread'
1903
    url = 'http://invisiblebread.com'
1904
1905
    @classmethod
1906
    def get_archive_elements(cls):
1907
        archive_url = urljoin_wrapper(cls.url, 'archives/')
1908
        return reversed(get_soup_at_url(archive_url).find_all('td', class_='archive-title'))
1909
1910
    @classmethod
1911
    def get_url_from_archive_element(cls, td):
1912
        return td.find('a')['href']
1913
1914
    @classmethod
1915
    def get_comic_info(cls, soup, td):
1916
        """Get information about a particular comics."""
1917
        url = cls.get_url_from_archive_element(td)
1918
        title = td.find('a').string
1919
        month_and_day = td.previous_sibling.string
1920
        link_re = re.compile('^%s/([0-9]+)/' % cls.url)
1921
        year = link_re.match(url).groups()[0]
1922
        date_str = month_and_day + ' ' + year
1923
        day = string_to_date(date_str, '%b %d %Y')
1924
        imgs = [soup.find('div', id='comic').find('img')]
1925
        assert len(imgs) == 1
1926
        assert all(i['title'] == i['alt'] == title for i in imgs)
1927
        return {
1928
            'month': day.month,
1929
            'year': day.year,
1930
            'day': day.day,
1931
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
1932 View Code Duplication
            'title': title,
1933
        }
1934
1935
1936
class DiscoBleach(GenericEmptyComic):  # Does not work anymore
1937
    """Class to retrieve Disco Bleach Comics."""
1938
    name = 'discobleach'
1939
    long_name = 'Disco Bleach'
1940
    url = 'http://discobleach.com'
1941
1942
1943
class TubeyToons(GenericEmptyComic):  # Does not work anymore
1944
    """Class to retrieve TubeyToons comics."""
1945
    # Also on http://tapastic.com/series/Tubey-Toons
1946
    # Also on http://tubeytoons.tumblr.com
1947
    name = 'tubeytoons'
1948
    long_name = 'Tubey Toons'
1949
    url = 'http://tubeytoons.com'
1950
    _categories = ('TUNEYTOONS', )
1951
1952
1953
class CompletelySeriousComics(GenericNavigableComic):
1954
    """Class to retrieve Completely Serious comics."""
1955
    name = 'completelyserious'
1956
    long_name = 'Completely Serious Comics'
1957
    url = 'http://completelyseriouscomics.com'
1958
    get_first_comic_link = get_a_navi_navifirst
1959
    get_navi_link = get_a_navi_navinext
1960
1961
    @classmethod
1962
    def get_comic_info(cls, soup, link):
1963
        """Get information about a particular comics."""
1964
        title = soup.find('h2', class_='post-title').string
1965
        author = soup.find('span', class_='post-author').contents[1].string
1966
        date_str = soup.find('span', class_='post-date').string
1967
        day = string_to_date(date_str, '%B %d, %Y')
1968
        imgs = soup.find('div', class_='comicpane').find_all('img')
1969
        assert imgs
1970
        alt = imgs[0]['title']
1971
        assert all(i['title'] == i['alt'] == alt for i in imgs)
1972
        return {
1973
            'month': day.month,
1974
            'year': day.year,
1975
            'day': day.day,
1976
            'img': [i['src'] for i in imgs],
1977
            'title': title,
1978
            'alt': alt,
1979
            'author': author,
1980
        }
1981
1982
1983
class PoorlyDrawnLines(GenericListableComic):
1984
    """Class to retrieve Poorly Drawn Lines comics."""
1985
    # Also on http://pdlcomics.tumblr.com
1986
    name = 'poorlydrawn'
1987 View Code Duplication
    long_name = 'Poorly Drawn Lines'
1988
    url = 'http://poorlydrawnlines.com'
1989
    _categories = ('POORLYDRAWN', )
1990
    get_url_from_archive_element = get_href
1991
1992
    @classmethod
1993
    def get_comic_info(cls, soup, link):
1994
        """Get information about a particular comics."""
1995
        imgs = soup.find('div', class_='post').find_all('img')
1996
        assert len(imgs) <= 1
1997
        return {
1998
            'img': [i['src'] for i in imgs],
1999
            'title': imgs[0].get('title', "") if imgs else "",
2000
        }
2001
2002
    @classmethod
2003
    def get_archive_elements(cls):
2004
        archive_url = urljoin_wrapper(cls.url, 'archive')
2005
        url_re = re.compile('^%s/comic/.' % cls.url)
2006
        return reversed(get_soup_at_url(archive_url).find_all('a', href=url_re))
2007
2008
2009
class LoadingComics(GenericNavigableComic):
2010
    """Class to retrieve Loading Artist comics."""
2011
    name = 'loadingartist'
2012
    long_name = 'Loading Artist'
2013
    url = 'http://www.loadingartist.com/latest'
2014
2015
    @classmethod
2016
    def get_first_comic_link(cls):
2017
        """Get link to first comics."""
2018
        return get_soup_at_url(cls.url).find('a', title="First")
2019 View Code Duplication
2020
    @classmethod
2021
    def get_navi_link(cls, last_soup, next_):
2022
        """Get link to next or previous comic."""
2023
        return last_soup.find('a', title='Next' if next_ else 'Previous')
2024
2025
    @classmethod
2026
    def get_comic_info(cls, soup, link):
2027
        """Get information about a particular comics."""
2028
        title = soup.find('h1').string
2029
        date_str = soup.find('span', class_='date').string.strip()
2030
        day = string_to_date(date_str, "%B %d, %Y")
2031
        imgs = soup.find('div', class_='comic').find_all('img', alt='', title='')
2032
        return {
2033
            'title': title,
2034
            'img': [i['src'] for i in imgs],
2035
            'month': day.month,
2036
            'year': day.year,
2037
            'day': day.day,
2038
        }
2039
2040
2041
class ChuckleADuck(GenericNavigableComic):
2042
    """Class to retrieve Chuckle-A-Duck comics."""
2043
    name = 'chuckleaduck'
2044
    long_name = 'Chuckle-A-duck'
2045
    url = 'http://chuckleaduck.com'
2046
    get_first_comic_link = get_div_navfirst_a
2047
    get_navi_link = get_link_rel_next
2048
2049
    @classmethod
2050
    def get_comic_info(cls, soup, link):
2051
        """Get information about a particular comics."""
2052
        date_str = soup.find('span', class_='post-date').string
2053
        day = string_to_date(remove_st_nd_rd_th_from_date(date_str), "%B %d, %Y")
2054
        author = soup.find('span', class_='post-author').string
2055
        div = soup.find('div', id='comic')
2056
        imgs = div.find_all('img') if div else []
2057
        title = imgs[0]['title'] if imgs else ""
2058
        assert all(i['title'] == i['alt'] == title for i in imgs)
2059
        return {
2060
            'month': day.month,
2061
            'year': day.year,
2062
            'day': day.day,
2063
            'img': [i['src'] for i in imgs],
2064
            'title': title,
2065
            'author': author,
2066
        }
2067
2068
2069
class DepressedAlien(GenericNavigableComic):
2070
    """Class to retrieve Depressed Alien Comics."""
2071
    name = 'depressedalien'
2072
    long_name = 'Depressed Alien'
2073
    url = 'http://depressedalien.com'
2074
    get_url_from_link = join_cls_url_to_href
2075
2076
    @classmethod
2077
    def get_first_comic_link(cls):
2078
        """Get link to first comics."""
2079
        return get_soup_at_url(cls.url).find('img', attrs={'name': 'beginArrow'}).parent
2080
2081
    @classmethod
2082
    def get_navi_link(cls, last_soup, next_):
2083
        """Get link to next or previous comic."""
2084
        return last_soup.find('img', attrs={'name': 'rightArrow' if next_ else 'leftArrow'}).parent
2085
2086
    @classmethod
2087
    def get_comic_info(cls, soup, link):
2088
        """Get information about a particular comics."""
2089
        title = soup.find('meta', attrs={'name': 'twitter:title'})['content']
2090
        imgs = soup.find_all('meta', property='og:image')
2091
        return {
2092
            'title': title,
2093
            'img': [i['content'] for i in imgs],
2094
        }
2095
2096
2097
class ThingsInSquares(GenericListableComic):
2098
    """Class to retrieve Things In Squares comics."""
2099
    # This can be retrieved in other languages
2100
    # Also on https://tapastic.com/series/Things-in-Squares
2101
    name = 'squares'
2102
    long_name = 'Things in squares'
2103
    url = 'http://www.thingsinsquares.com'
2104
2105
    @classmethod
2106
    def get_comic_info(cls, soup, tr):
2107
        """Get information about a particular comics."""
2108
        _, td2, td3 = tr.find_all('td')
2109
        a = td2.find('a')
2110
        date_str = td3.string
2111
        day = string_to_date(date_str, "%m.%d.%y")
2112
        title = a.string
2113
        title2 = soup.find('meta', property='og:title')['content']
2114
        desc = soup.find('meta', property='og:description')
2115
        description = desc['content'] if desc else ''
2116
        tags = ' '.join(t['content'] for t in soup.find_all('meta', property='article:tag'))
2117
        imgs = soup.find('div', class_='entry-content').find_all('img')
2118
        return {
2119 View Code Duplication
            'day': day.day,
2120
            'month': day.month,
2121
            'year': day.year,
2122
            'title': title,
2123
            'title2': title2,
2124
            'description': description,
2125
            'tags': tags,
2126
            'img': [i['src'] for i in imgs],
2127
            'alt': ' '.join(i['alt'] for i in imgs),
2128
        }
2129
2130
    @classmethod
2131
    def get_url_from_archive_element(cls, tr):
2132
        _, td2, td3 = tr.find_all('td')
2133
        return td2.find('a')['href']
2134
2135
    @classmethod
2136
    def get_archive_elements(cls):
2137
        archive_url = urljoin_wrapper(cls.url, 'archive-2')
2138
        return reversed(get_soup_at_url(archive_url).find('tbody').find_all('tr'))
2139
2140
2141
class HappleTea(GenericNavigableComic):
2142
    """Class to retrieve Happle Tea Comics."""
2143
    name = 'happletea'
2144
    long_name = 'Happle Tea'
2145
    url = 'http://www.happletea.com'
2146
    get_first_comic_link = get_a_navi_navifirst
2147
    get_navi_link = get_link_rel_next
2148
2149
    @classmethod
2150
    def get_comic_info(cls, soup, link):
2151
        """Get information about a particular comics."""
2152
        imgs = soup.find('div', id='comic').find_all('img')
2153
        post = soup.find('div', class_='post-content')
2154
        title = post.find('h2', class_='post-title').string
2155
        author = post.find('a', rel='author').string
2156
        date_str = post.find('span', class_='post-date').string
2157
        day = string_to_date(date_str, "%B %d, %Y")
2158
        assert all(i['alt'] == i['title'] for i in imgs)
2159
        return {
2160
            'title': title,
2161
            'img': [i['src'] for i in imgs],
2162
            'alt': ''.join(i['alt'] for i in imgs),
2163
            'month': day.month,
2164
            'year': day.year,
2165
            'day': day.day,
2166
            'author': author,
2167
        }
2168
2169
2170
class FatAwesomeComics(GenericNavigableComic):
2171
    """Class to retrieve Fat Awesome Comics."""
2172
    # Also on http://fatawesomecomedy.tumblr.com
2173
    name = 'fatawesome'
2174
    long_name = 'Fat Awesome'
2175
    url = 'http://fatawesome.com/comics'
2176
    get_navi_link = get_a_rel_next
2177
    get_first_comic_link = simulate_first_link
2178
    first_url = 'http://fatawesome.com/shortbus/'
2179
2180
    @classmethod
2181
    def get_comic_info(cls, soup, link):
2182
        """Get information about a particular comics."""
2183
        title = soup.find('meta', attrs={'name': 'twitter:title'})['content']
2184
        description = soup.find('meta', attrs={'name': 'description'})['content']
2185
        tags_prop = soup.find('meta', property='article:tag')
2186
        tags = tags_prop['content'] if tags_prop else ""
2187
        date_str = soup.find('meta', property='article:published_time')['content'][:10]
2188
        day = string_to_date(date_str, "%Y-%m-%d")
2189
        imgs = soup.find_all('img', attrs={'data-recalc-dims': "1"})
2190
        assert len(imgs) == 1
2191
        return {
2192
            'title': title,
2193
            'description': description,
2194
            'tags': tags,
2195
            'alt': "".join(i['alt'] for i in imgs),
2196
            'img': [i['src'].rsplit('?', 1)[0] for i in imgs],
2197
            'month': day.month,
2198
            'year': day.year,
2199
            'day': day.day,
2200
        }
2201
2202
2203
class AnythingComic(GenericListableComic):
2204
    """Class to retrieve Anything Comics."""
2205
    # Also on http://tapastic.com/series/anything
2206
    name = 'anythingcomic'
2207
    long_name = 'Anything Comic'
2208
    url = 'http://www.anythingcomic.com'
2209
2210
    @classmethod
2211
    def get_archive_elements(cls):
2212
        archive_url = urljoin_wrapper(cls.url, 'archive/')
2213
        # The first 2 <tr>'s do not correspond to comics
2214
        return get_soup_at_url(archive_url).find('table', id='chapter_table').find_all('tr')[2:]
2215
2216
    @classmethod
2217
    def get_url_from_archive_element(cls, tr):
2218
        """Get url corresponding to an archive element."""
2219
        td_num, td_comic, td_date, _ = tr.find_all('td')
2220
        link = td_comic.find('a')
2221
        return urljoin_wrapper(cls.url, link['href'])
2222
2223
    @classmethod
2224
    def get_comic_info(cls, soup, tr):
2225
        """Get information about a particular comics."""
2226
        td_num, td_comic, td_date, _ = tr.find_all('td')
2227
        num = int(td_num.string)
2228
        link = td_comic.find('a')
2229
        title = link.string
2230
        imgs = soup.find_all('img', id='comic_image')
2231
        date_str = td_date.string
2232
        day = string_to_date(remove_st_nd_rd_th_from_date(date_str), "%B %d, %Y, %I:%M %p")
2233
        assert len(imgs) == 1
2234
        assert all(i.get('alt') == i.get('title') for i in imgs)
2235
        return {
2236
            'num': num,
2237
            'title': title,
2238
            'alt': imgs[0].get('alt', ''),
2239
            'img': [i['src'] for i in imgs],
2240
            'month': day.month,
2241
            'year': day.year,
2242
            'day': day.day,
2243
        }
2244
2245
2246
class LonnieMillsap(GenericNavigableComic):
2247
    """Class to retrieve Lonnie Millsap's comics."""
2248
    name = 'millsap'
2249
    long_name = 'Lonnie Millsap'
2250
    url = 'http://www.lonniemillsap.com'
2251
    get_navi_link = get_link_rel_next
2252
    get_first_comic_link = simulate_first_link
2253
    first_url = 'http://www.lonniemillsap.com/?p=42'
2254
2255
    @classmethod
2256
    def get_comic_info(cls, soup, link):
2257
        """Get information about a particular comics."""
2258
        title = soup.find('h2', class_='post-title').string
2259
        post = soup.find('div', class_='post-content')
2260
        author = post.find("span", class_="post-author").find("a").string
2261
        date_str = post.find("span", class_="post-date").string
2262
        day = string_to_date(date_str, "%B %d, %Y")
2263
        imgs = post.find("div", class_="entry").find_all("img")
2264
        return {
2265
            'title': title,
2266
            'author': author,
2267
            'img': [i['src'] for i in imgs],
2268
            'month': day.month,
2269
            'year': day.year,
2270
            'day': day.day,
2271
        }
2272
2273
2274
class LinsEditions(GenericNavigableComic):
2275
    """Class to retrieve L.I.N.S. Editions comics."""
2276
    # Also on http://linscomics.tumblr.com
2277
    name = 'lins'
2278
    long_name = 'L.I.N.S. Editions'
2279
    url = 'https://linsedition.com'
2280
    _categories = ('LINS', )
2281
    get_navi_link = get_link_rel_next
2282
    get_first_comic_link = simulate_first_link
2283
    first_url = 'https://linsedition.com/2011/09/07/l-i-n-s/'
2284
2285
    @classmethod
2286
    def get_comic_info(cls, soup, link):
2287
        """Get information about a particular comics."""
2288
        title = soup.find('meta', property='og:title')['content']
2289
        imgs = soup.find_all('meta', property='og:image')
2290
        date_str = soup.find('meta', property='article:published_time')['content'][:10]
2291
        day = string_to_date(date_str, "%Y-%m-%d")
2292
        return {
2293
            'title': title,
2294
            'img': [i['content'] for i in imgs],
2295
            'month': day.month,
2296
            'year': day.year,
2297
            'day': day.day,
2298
        }
2299
2300
2301
class ThorsThundershack(GenericNavigableComic):
2302
    """Class to retrieve Thor's Thundershack comics."""
2303
    # Also on http://tapastic.com/series/Thors-Thundershac
2304
    name = 'thor'
2305
    long_name = 'Thor\'s Thundershack'
2306
    url = 'http://www.thorsthundershack.com'
2307
    _categories = ('THOR', )
2308
    get_url_from_link = join_cls_url_to_href
2309
2310
    @classmethod
2311
    def get_first_comic_link(cls):
2312
        """Get link to first comics."""
2313
        return get_soup_at_url(cls.url).find('a', class_='first navlink')
2314
2315
    @classmethod
2316
    def get_navi_link(cls, last_soup, next_):
2317
        """Get link to next or previous comic."""
2318
        for link in last_soup.find_all('a', rel='next' if next_ else 'prev'):
2319
            if link['href'] != '/comic':
2320
                return link
2321 View Code Duplication
        return None
2322
2323
    @classmethod
2324
    def get_comic_info(cls, soup, link):
2325
        """Get information about a particular comics."""
2326
        title = soup.find('meta', attrs={'name': 'description'})["content"]
2327
        description = soup.find('div', itemprop='articleBody').text
2328
        author = soup.find('span', itemprop='author copyrightHolder').string
2329
        imgs = soup.find_all('img', itemprop='image')
2330
        assert all(i['title'] == i['alt'] for i in imgs)
2331
        alt = imgs[0]['alt'] if imgs else ""
2332
        date_str = soup.find('time', itemprop='datePublished')["datetime"]
2333
        day = string_to_date(date_str, "%Y-%m-%d %H:%M:%S")
2334
        return {
2335
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
2336
            'month': day.month,
2337
            'year': day.year,
2338
            'day': day.day,
2339
            'author': author,
2340
            'title': title,
2341
            'alt': alt,
2342
            'description': description,
2343
        }
2344
2345
2346
class GerbilWithAJetpack(GenericNavigableComic):
2347
    """Class to retrieve GerbilWithAJetpack comics."""
2348
    name = 'gerbil'
2349
    long_name = 'Gerbil With A Jetpack'
2350
    url = 'http://gerbilwithajetpack.com'
2351
    get_first_comic_link = get_a_navi_navifirst
2352
    get_navi_link = get_a_rel_next
2353
2354
    @classmethod
2355
    def get_comic_info(cls, soup, link):
2356
        """Get information about a particular comics."""
2357
        title = soup.find('h2', class_='post-title').string
2358
        author = soup.find("span", class_="post-author").find("a").string
2359
        date_str = soup.find("span", class_="post-date").string
2360
        day = string_to_date(date_str, "%B %d, %Y")
2361
        imgs = soup.find("div", id="comic").find_all("img")
2362
        alt = imgs[0]['alt']
2363
        assert all(i['alt'] == i['title'] == alt for i in imgs)
2364
        return {
2365
            'img': [i['src'] for i in imgs],
2366
            'title': title,
2367
            'alt': alt,
2368
            'author': author,
2369
            'day': day.day,
2370
            'month': day.month,
2371
            'year': day.year
2372
        }
2373
2374
2375
class EveryDayBlues(GenericNavigableComic):
2376
    """Class to retrieve EveryDayBlues Comics."""
2377
    name = "blues"
2378 View Code Duplication
    long_name = "Every Day Blues"
2379
    url = "http://everydayblues.net"
2380
    get_first_comic_link = get_a_navi_navifirst
2381
    get_navi_link = get_link_rel_next
2382
2383
    @classmethod
2384
    def get_comic_info(cls, soup, link):
2385
        """Get information about a particular comics."""
2386
        title = soup.find("h2", class_="post-title").string
2387
        author = soup.find("span", class_="post-author").find("a").string
2388
        date_str = soup.find("span", class_="post-date").string
2389
        day = string_to_date(date_str, "%d. %B %Y", "de_DE.utf8")
2390
        imgs = soup.find("div", id="comic").find_all("img")
2391
        assert all(i['alt'] == i['title'] == title for i in imgs)
2392
        assert len(imgs) <= 1
2393
        return {
2394
            'img': [i['src'] for i in imgs],
2395
            'title': title,
2396
            'author': author,
2397
            'day': day.day,
2398
            'month': day.month,
2399
            'year': day.year
2400
        }
2401
2402
2403
class BiterComics(GenericNavigableComic):
2404
    """Class to retrieve Biter Comics."""
2405
    name = "biter"
2406
    long_name = "Biter Comics"
2407
    url = "http://www.bitercomics.com"
2408
    get_first_comic_link = get_a_navi_navifirst
2409
    get_navi_link = get_link_rel_next
2410
2411
    @classmethod
2412
    def get_comic_info(cls, soup, link):
2413
        """Get information about a particular comics."""
2414
        title = soup.find("h1", class_="entry-title").string
2415
        author = soup.find("span", class_="author vcard").find("a").string
2416
        date_str = soup.find("span", class_="entry-date").string
2417
        day = string_to_date(date_str, "%B %d, %Y")
2418
        imgs = soup.find("div", id="comic").find_all("img")
2419
        assert all(i['alt'] == i['title'] for i in imgs)
2420
        assert len(imgs) == 1
2421
        alt = imgs[0]['alt']
2422
        return {
2423
            'img': [i['src'] for i in imgs],
2424
            'title': title,
2425
            'alt': alt,
2426
            'author': author,
2427
            'day': day.day,
2428
            'month': day.month,
2429
            'year': day.year
2430
        }
2431
2432
2433
class TheAwkwardYeti(GenericNavigableComic):
2434
    """Class to retrieve The Awkward Yeti comics."""
2435
    # Also on http://www.gocomics.com/the-awkward-yeti
2436
    # Also on http://larstheyeti.tumblr.com
2437
    # Also on https://tapastic.com/series/TheAwkwardYeti
2438
    name = 'yeti'
2439
    long_name = 'The Awkward Yeti'
2440
    url = 'http://theawkwardyeti.com'
2441
    _categories = ('YETI', )
2442
    get_first_comic_link = get_a_navi_navifirst
2443
    get_navi_link = get_link_rel_next
2444
2445
    @classmethod
2446
    def get_comic_info(cls, soup, link):
2447
        """Get information about a particular comics."""
2448
        title = soup.find('h2', class_='post-title').string
2449
        date_str = soup.find("span", class_="post-date").string
2450
        day = string_to_date(date_str, "%B %d, %Y")
2451
        imgs = soup.find("div", id="comic").find_all("img")
2452
        assert all(idx > 0 or i['alt'] == i['title'] for idx, i in enumerate(imgs))
2453
        return {
2454
            'img': [i['src'] for i in imgs],
2455
            'title': title,
2456
            'day': day.day,
2457
            'month': day.month,
2458
            'year': day.year
2459
        }
2460
2461
2462
class PleasantThoughts(GenericNavigableComic):
2463
    """Class to retrieve Pleasant Thoughts comics."""
2464
    name = 'pleasant'
2465
    long_name = 'Pleasant Thoughts'
2466
    url = 'http://pleasant-thoughts.com'
2467
    get_first_comic_link = get_a_navi_navifirst
2468
    get_navi_link = get_link_rel_next
2469
2470
    @classmethod
2471
    def get_comic_info(cls, soup, link):
2472
        """Get information about a particular comics."""
2473
        post = soup.find('div', class_='post-content')
2474
        title = post.find('h2', class_='post-title').string
2475
        imgs = post.find("div", class_="entry").find_all("img")
2476
        return {
2477
            'title': title,
2478
            'img': [i['src'] for i in imgs],
2479
        }
2480
2481
2482
class MisterAndMe(GenericNavigableComic):
2483
    """Class to retrieve Mister & Me Comics."""
2484
    # Also on http://www.gocomics.com/mister-and-me
2485
    # Also on https://tapastic.com/series/Mister-and-Me
2486
    name = 'mister'
2487
    long_name = 'Mister & Me'
2488 View Code Duplication
    url = 'http://www.mister-and-me.com'
2489
    get_first_comic_link = get_a_comicnavbase_comicnavfirst
2490
    get_navi_link = get_link_rel_next
2491
2492
    @classmethod
2493
    def get_comic_info(cls, soup, link):
2494
        """Get information about a particular comics."""
2495
        title = soup.find('h2', class_='post-title').string
2496
        author = soup.find("span", class_="post-author").find("a").string
2497
        date_str = soup.find("span", class_="post-date").string
2498
        day = string_to_date(date_str, "%B %d, %Y")
2499
        imgs = soup.find("div", id="comic").find_all("img")
2500
        assert all(i['alt'] == i['title'] for i in imgs)
2501
        assert len(imgs) <= 1
2502
        alt = imgs[0]['alt'] if imgs else ""
2503
        return {
2504
            'img': [i['src'] for i in imgs],
2505
            'title': title,
2506
            'alt': alt,
2507
            'author': author,
2508
            'day': day.day,
2509
            'month': day.month,
2510
            'year': day.year
2511
        }
2512
2513
2514
class LastPlaceComics(GenericNavigableComic):
2515
    """Class to retrieve Last Place Comics."""
2516
    name = 'lastplace'
2517
    long_name = 'Last Place Comics'
2518 View Code Duplication
    url = "http://lastplacecomics.com"
2519
    get_first_comic_link = get_a_comicnavbase_comicnavfirst
2520
    get_navi_link = get_link_rel_next
2521
2522
    @classmethod
2523
    def get_comic_info(cls, soup, link):
2524
        """Get information about a particular comics."""
2525
        title = soup.find('h2', class_='post-title').string
2526
        author = soup.find("span", class_="post-author").find("a").string
2527
        date_str = soup.find("span", class_="post-date").string
2528
        day = string_to_date(date_str, "%B %d, %Y")
2529
        imgs = soup.find("div", id="comic").find_all("img")
2530
        assert all(i['alt'] == i['title'] for i in imgs)
2531
        assert len(imgs) <= 1
2532
        alt = imgs[0]['alt'] if imgs else ""
2533
        return {
2534
            'img': [i['src'] for i in imgs],
2535
            'title': title,
2536
            'alt': alt,
2537
            'author': author,
2538
            'day': day.day,
2539
            'month': day.month,
2540
            'year': day.year
2541
        }
2542
2543
2544
class TalesOfAbsurdity(GenericNavigableComic):
2545
    """Class to retrieve Tales Of Absurdity comics."""
2546
    # Also on http://tapastic.com/series/Tales-Of-Absurdity
2547
    # Also on http://talesofabsurdity.tumblr.com
2548
    name = 'absurdity'
2549
    long_name = 'Tales of Absurdity'
2550
    url = 'http://talesofabsurdity.com'
2551
    _categories = ('ABSURDITY', )
2552
    get_first_comic_link = get_a_navi_navifirst
2553
    get_navi_link = get_a_navi_comicnavnext_navinext
2554
2555
    @classmethod
2556
    def get_comic_info(cls, soup, link):
2557
        """Get information about a particular comics."""
2558
        title = soup.find('h2', class_='post-title').string
2559
        author = soup.find("span", class_="post-author").find("a").string
2560
        date_str = soup.find("span", class_="post-date").string
2561
        day = string_to_date(date_str, "%B %d, %Y")
2562
        imgs = soup.find("div", id="comic").find_all("img")
2563
        assert all(i['alt'] == i['title'] for i in imgs)
2564
        alt = imgs[0]['alt'] if imgs else ""
2565
        return {
2566
            'img': [i['src'] for i in imgs],
2567
            'title': title,
2568
            'alt': alt,
2569
            'author': author,
2570
            'day': day.day,
2571
            'month': day.month,
2572
            'year': day.year
2573
        }
2574
2575
2576
class EndlessOrigami(GenericNavigableComic):
2577
    """Class to retrieve Endless Origami Comics."""
2578
    name = "origami"
2579
    long_name = "Endless Origami"
2580
    url = "http://endlessorigami.com"
2581
    get_first_comic_link = get_a_navi_navifirst
2582
    get_navi_link = get_link_rel_next
2583
2584
    @classmethod
2585
    def get_comic_info(cls, soup, link):
2586
        """Get information about a particular comics."""
2587
        title = soup.find('h2', class_='post-title').string
2588
        author = soup.find("span", class_="post-author").find("a").string
2589
        date_str = soup.find("span", class_="post-date").string
2590
        day = string_to_date(date_str, "%B %d, %Y")
2591
        imgs = soup.find("div", id="comic").find_all("img")
2592
        assert all(i['alt'] == i['title'] for i in imgs)
2593
        alt = imgs[0]['alt'] if imgs else ""
2594
        return {
2595
            'img': [i['src'] for i in imgs],
2596
            'title': title,
2597
            'alt': alt,
2598
            'author': author,
2599
            'day': day.day,
2600
            'month': day.month,
2601
            'year': day.year
2602
        }
2603
2604
2605
class PlanC(GenericNavigableComic):
2606
    """Class to retrieve Plan C comics."""
2607
    name = 'planc'
2608
    long_name = 'Plan C'
2609
    url = 'http://www.plancomic.com'
2610
    get_first_comic_link = get_a_navi_navifirst
2611
    get_navi_link = get_a_navi_comicnavnext_navinext
2612
2613
    @classmethod
2614
    def get_comic_info(cls, soup, link):
2615
        """Get information about a particular comics."""
2616
        title = soup.find('h2', class_='post-title').string
2617
        date_str = soup.find("span", class_="post-date").string
2618
        day = string_to_date(date_str, "%B %d, %Y")
2619
        imgs = soup.find('div', id='comic').find_all('img')
2620
        return {
2621
            'title': title,
2622
            'img': [i['src'] for i in imgs],
2623
            'month': day.month,
2624
            'year': day.year,
2625
            'day': day.day,
2626 View Code Duplication
        }
2627
2628
2629
class BuniComic(GenericNavigableComic):
2630
    """Class to retrieve Buni Comics."""
2631
    name = 'buni'
2632
    long_name = 'BuniComics'
2633
    url = 'http://www.bunicomic.com'
2634
    get_first_comic_link = get_a_comicnavbase_comicnavfirst
2635
    get_navi_link = get_link_rel_next
2636
2637
    @classmethod
2638
    def get_comic_info(cls, soup, link):
2639
        """Get information about a particular comics."""
2640
        imgs = soup.find('div', id='comic').find_all('img')
2641
        assert all(i['alt'] == i['title'] for i in imgs)
2642
        assert len(imgs) == 1
2643
        return {
2644
            'img': [i['src'] for i in imgs],
2645
            'title': imgs[0]['title'],
2646
        }
2647
2648
2649
class GenericCommitStrip(GenericNavigableComic):
2650
    """Generic class to retrieve Commit Strips in different languages."""
2651
    get_navi_link = get_a_rel_next
2652
    get_first_comic_link = simulate_first_link
2653
    first_url = NotImplemented
2654
2655
    @classmethod
2656
    def get_comic_info(cls, soup, link):
2657
        """Get information about a particular comics."""
2658
        desc = soup.find('meta', property='og:description')['content']
2659 View Code Duplication
        title = soup.find('meta', property='og:title')['content']
2660
        imgs = soup.find('div', class_='entry-content').find_all('img')
2661
        title2 = ' '.join(i.get('title', '') for i in imgs)
2662
        return {
2663
            'title': title,
2664
            'title2': title2,
2665
            'description': desc,
2666
            'img': [urljoin_wrapper(cls.url, convert_iri_to_plain_ascii_uri(i['src'])) for i in imgs],
2667
        }
2668
2669
2670
class CommitStripFr(GenericCommitStrip):
2671
    """Class to retrieve Commit Strips in French."""
2672
    name = 'commit_fr'
2673
    long_name = 'Commit Strip (Fr)'
2674
    url = 'http://www.commitstrip.com/fr'
2675
    _categories = ('FRANCAIS', )
2676
    first_url = 'http://www.commitstrip.com/fr/2012/02/22/interview/'
2677
2678
2679
class CommitStripEn(GenericCommitStrip):
2680
    """Class to retrieve Commit Strips in English."""
2681
    name = 'commit_en'
2682
    long_name = 'Commit Strip (En)'
2683
    url = 'http://www.commitstrip.com/en'
2684
    first_url = 'http://www.commitstrip.com/en/2012/02/22/interview/'
2685
2686
2687
class GenericBoumerie(GenericNavigableComic):
2688
    """Generic class to retrieve Boumeries comics in different languages."""
2689
    get_first_comic_link = get_a_navi_navifirst
2690
    get_navi_link = get_link_rel_next
2691
    date_format = NotImplemented
2692
    lang = NotImplemented
2693
2694
    @classmethod
2695
    def get_comic_info(cls, soup, link):
2696
        """Get information about a particular comics."""
2697
        title = soup.find('h2', class_='post-title').string
2698
        short_url = soup.find('link', rel='shortlink')['href']
2699
        author = soup.find("span", class_="post-author").find("a").string
2700
        date_str = soup.find('span', class_='post-date').string
2701
        day = string_to_date(date_str, cls.date_format, cls.lang)
2702
        imgs = soup.find('div', id='comic').find_all('img')
2703
        assert all(i['alt'] == i['title'] for i in imgs)
2704
        return {
2705
            'short_url': short_url,
2706
            'img': [i['src'] for i in imgs],
2707
            'title': title,
2708
            'author': author,
2709
            'month': day.month,
2710
            'year': day.year,
2711
            'day': day.day,
2712
        }
2713
2714
2715
class BoumerieEn(GenericBoumerie):
2716
    """Class to retrieve Boumeries comics in English."""
2717
    name = 'boumeries_en'
2718
    long_name = 'Boumeries (En)'
2719
    url = 'http://comics.boumerie.com'
2720
    date_format = "%B %d, %Y"
2721
    lang = 'en_GB.UTF-8'
2722
2723
2724
class BoumerieFr(GenericBoumerie):
2725
    """Class to retrieve Boumeries comics in French."""
2726
    name = 'boumeries_fr'
2727
    long_name = 'Boumeries (Fr)'
2728
    url = 'http://bd.boumerie.com'
2729
    _categories = ('FRANCAIS', )
2730
    date_format = "%A, %d %B %Y"
2731
    lang = "fr_FR.utf8"
2732
2733
2734
class UnearthedComics(GenericNavigableComic):
2735
    """Class to retrieve Unearthed comics."""
2736
    # Also on http://tapastic.com/series/UnearthedComics
2737
    # Also on http://unearthedcomics.tumblr.com
2738 View Code Duplication
    name = 'unearthed'
2739
    long_name = 'Unearthed Comics'
2740
    url = 'http://unearthedcomics.com'
2741
    _categories = ('UNEARTHED', )
2742
    get_navi_link = get_link_rel_next
2743
    get_first_comic_link = simulate_first_link
2744
    first_url = 'http://unearthedcomics.com/comics/world-with-turn-signals/'
2745
2746
    @classmethod
2747
    def get_comic_info(cls, soup, link):
2748
        """Get information about a particular comics."""
2749
        short_url = soup.find('link', rel='shortlink')['href']
2750
        title_elt = soup.find('h1') or soup.find('h2')
2751
        title = title_elt.string if title_elt else ""
2752
        desc = soup.find('meta', property='og:description')
2753
        date_str = soup.find('time', class_='published updated hidden')['datetime']
2754
        day = string_to_date(date_str, "%Y-%m-%d")
2755
        post = soup.find('div', class_="entry content entry-content type-portfolio")
2756
        imgs = post.find_all('img')
2757
        return {
2758
            'title': title,
2759
            'description': desc,
2760
            'url2': short_url,
2761
            'img': [i['src'] for i in imgs],
2762
            'month': day.month,
2763
            'year': day.year,
2764
            'day': day.day,
2765
        }
2766
2767
2768
class Optipess(GenericNavigableComic):
2769
    """Class to retrieve Optipess comics."""
2770
    name = 'optipess'
2771
    long_name = 'Optipess'
2772
    url = 'http://www.optipess.com'
2773
    get_first_comic_link = get_a_navi_navifirst
2774
    get_navi_link = get_link_rel_next
2775
2776
    @classmethod
2777
    def get_comic_info(cls, soup, link):
2778
        """Get information about a particular comics."""
2779
        title = soup.find('h2', class_='post-title').string
2780
        author = soup.find("span", class_="post-author").find("a").string
2781
        comic = soup.find('div', id='comic')
2782
        imgs = comic.find_all('img') if comic else []
2783
        alt = imgs[0]['title'] if imgs else ""
2784
        assert all(i['alt'] == i['title'] == alt for i in imgs)
2785
        date_str = soup.find('span', class_='post-date').string
2786
        day = string_to_date(date_str, "%B %d, %Y")
2787
        return {
2788
            'title': title,
2789
            'alt': alt,
2790
            'author': author,
2791
            'img': [i['src'] for i in imgs],
2792
            'month': day.month,
2793
            'year': day.year,
2794
            'day': day.day,
2795
        }
2796
2797
2798
class PainTrainComic(GenericNavigableComic):
2799
    """Class to retrieve Pain Train Comics."""
2800
    name = 'paintrain'
2801
    long_name = 'Pain Train Comics'
2802
    url = 'http://paintraincomic.com'
2803
    get_first_comic_link = get_a_navi_navifirst
2804
    get_navi_link = get_link_rel_next
2805
2806
    @classmethod
2807
    def get_comic_info(cls, soup, link):
2808
        """Get information about a particular comics."""
2809
        title = soup.find('h2', class_='post-title').string
2810
        short_url = soup.find('link', rel='shortlink')['href']
2811
        short_url_re = re.compile('^%s/\\?p=([0-9]*)' % cls.url)
2812
        num = int(short_url_re.match(short_url).groups()[0])
2813
        imgs = soup.find('div', id='comic').find_all('img')
2814
        alt = imgs[0]['title']
2815
        assert all(i['alt'] == i['title'] == alt for i in imgs)
2816
        date_str = soup.find('span', class_='post-date').string
2817
        day = string_to_date(date_str, "%d/%m/%Y")
2818
        return {
2819
            'short_url': short_url,
2820
            'num': num,
2821
            'img': [i['src'] for i in imgs],
2822
            'month': day.month,
2823
            'year': day.year,
2824
            'day': day.day,
2825
            'alt': alt,
2826
            'title': title,
2827
        }
2828
2829
2830
class MoonBeard(GenericNavigableComic):
2831
    """Class to retrieve MoonBeard comics."""
2832
    # Also on http://blog.squiresjam.es/moonbeard
2833
    # Also on http://www.webtoons.com/en/comedy/moon-beard/list?title_no=471
2834
    name = 'moonbeard'
2835
    long_name = 'Moon Beard'
2836
    url = 'http://moonbeard.com'
2837
    get_first_comic_link = get_a_navi_navifirst
2838
    get_navi_link = get_a_navi_navinext
2839
2840
    @classmethod
2841
    def get_comic_info(cls, soup, link):
2842
        """Get information about a particular comics."""
2843
        title = soup.find('h2', class_='post-title').string
2844
        short_url = soup.find('link', rel='shortlink')['href']
2845
        short_url_re = re.compile('^%s/\\?p=([0-9]*)' % cls.url)
2846
        num = int(short_url_re.match(short_url).groups()[0])
2847
        imgs = soup.find('div', id='comic').find_all('img')
2848
        alt = imgs[0]['title']
2849
        assert all(i['alt'] == i['title'] == alt for i in imgs)
2850
        date_str = soup.find('span', class_='post-date').string
2851
        day = string_to_date(date_str, "%B %d, %Y")
2852
        tags = ' '.join(t['content'] for t in soup.find_all('meta', property='article:tag'))
2853
        author = soup.find('span', class_='post-author').string
2854
        return {
2855
            'short_url': short_url,
2856
            'num': num,
2857
            'img': [i['src'] for i in imgs],
2858
            'month': day.month,
2859
            'year': day.year,
2860
            'day': day.day,
2861
            'title': title,
2862
            'tags': tags,
2863
            'alt': alt,
2864
            'author': author,
2865
        }
2866
2867
2868
class AHamADay(GenericNavigableComic):
2869 View Code Duplication
    """Class to retrieve class A Ham A Day comics."""
2870
    name = 'ham'
2871
    long_name = 'A Ham A Day'
2872
    url = 'http://www.ahammaday.com'
2873
    get_url_from_link = join_cls_url_to_href
2874
    get_first_comic_link = simulate_first_link
2875
    first_url = 'http://www.ahammaday.com/today/3/6/french'
2876
2877
    @classmethod
2878
    def get_navi_link(cls, last_soup, next_):
2879
        """Get link to next or previous comic."""
2880
        # prev is next / next is prev
2881
        return last_soup.find('li', class_='previous' if next_ else 'next').find('a')
2882
2883
    @classmethod
2884
    def get_comic_info(cls, soup, link):
2885
        """Get information about a particular comics."""
2886
        date_str = soup.find('time', class_='published')['datetime']
2887
        day = string_to_date(date_str, "%Y-%m-%d")
2888
        author = soup.find('span', class_='blog-author').find('a').string
2889
        title = soup.find('meta', property='og:title')['content']
2890
        imgs = soup.find_all('meta', itemprop='image')
2891
        return {
2892
            'img': [i['content'] for i in imgs],
2893
            'title': title,
2894
            'author': author,
2895
            'day': day.day,
2896
            'month': day.month,
2897
            'year': day.year,
2898
        }
2899
2900
2901
class LittleLifeLines(GenericNavigableComic):
2902
    """Class to retrieve Little Life Lines comics."""
2903
    # Also on https://little-life-lines.tumblr.com
2904
    name = 'life'
2905
    long_name = 'Little Life Lines'
2906
    url = 'http://www.littlelifelines.com'
2907
    get_url_from_link = join_cls_url_to_href
2908
    get_first_comic_link = simulate_first_link
2909
    first_url = 'http://www.littlelifelines.com/comics/well-done'
2910
2911
    @classmethod
2912
    def get_navi_link(cls, last_soup, next_):
2913
        """Get link to next or previous comic."""
2914
        # prev is next / next is prev
2915
        li = last_soup.find('li', class_='prev' if next_ else 'next')
2916
        return li.find('a') if li else None
2917
2918
    @classmethod
2919
    def get_comic_info(cls, soup, link):
2920
        """Get information about a particular comics."""
2921
        title = soup.find('meta', property='og:title')['content']
2922
        desc = soup.find('meta', property='og:description')['content']
2923
        date_str = soup.find('time', class_='published')['datetime']
2924
        day = string_to_date(date_str, "%Y-%m-%d")
2925
        author = soup.find('a', rel='author').string
2926
        div_content = soup.find('div', class_="body entry-content")
2927
        imgs = div_content.find_all('img')
2928
        imgs = [i for i in imgs if i.get('src') is not None]
2929
        alt = imgs[0]['alt']
2930
        return {
2931
            'title': title,
2932
            'alt': alt,
2933
            'description': desc,
2934
            'author': author,
2935
            'day': day.day,
2936
            'month': day.month,
2937
            'year': day.year,
2938
            'img': [i['src'] for i in imgs],
2939
        }
2940
2941
2942
class GenericWordPressInkblot(GenericNavigableComic):
2943
    """Generic class to retrieve comics using WordPress with Inkblot."""
2944
    get_navi_link = get_link_rel_next
2945
2946
    @classmethod
2947
    def get_first_comic_link(cls):
2948
        """Get link to first comics."""
2949
        return get_soup_at_url(cls.url).find('a', class_='webcomic-link webcomic1-link first-webcomic-link first-webcomic1-link')
2950
2951
    @classmethod
2952
    def get_comic_info(cls, soup, link):
2953
        """Get information about a particular comics."""
2954
        title = soup.find('meta', property='og:title')['content']
2955
        imgs = soup.find('div', class_='webcomic-image').find_all('img')
2956
        date_str = soup.find('meta', property='article:published_time')['content'][:10]
2957
        day = string_to_date(date_str, "%Y-%m-%d")
2958
        return {
2959
            'title': title,
2960
            'day': day.day,
2961
            'month': day.month,
2962
            'year': day.year,
2963
            'img': [i['src'] for i in imgs],
2964
        }
2965
2966
2967
class EverythingsStupid(GenericWordPressInkblot):
2968
    """Class to retrieve Everything's stupid Comics."""
2969
    # Also on http://tapastic.com/series/EverythingsStupid
2970
    # Also on http://www.webtoons.com/en/challenge/everythings-stupid/list?title_no=14591
2971
    # Also on http://everythingsstupidcomics.tumblr.com
2972
    name = 'stupid'
2973
    long_name = "Everything's Stupid"
2974
    url = 'http://everythingsstupid.net'
2975
2976
2977
class TheIsmComics(GenericWordPressInkblot):
2978
    """Class to retrieve The Ism Comics."""
2979
    # Also on https://tapastic.com/series/TheIsm (?)
2980
    name = 'theism'
2981
    long_name = "The Ism"
2982
    url = 'http://www.theism-comics.com'
2983
2984
2985
class WoodenPlankStudios(GenericWordPressInkblot):
2986
    """Class to retrieve Wooden Plank Studios comics."""
2987
    name = 'woodenplank'
2988
    long_name = 'Wooden Plank Studios'
2989
    url = 'http://woodenplankstudios.com'
2990
2991
2992
class ElectricBunnyComic(GenericNavigableComic):
2993
    """Class to retrieve Electric Bunny Comics."""
2994
    # Also on http://electricbunnycomics.tumblr.com
2995
    name = 'bunny'
2996
    long_name = 'Electric Bunny Comic'
2997
    url = 'http://www.electricbunnycomics.com/View/Comic/153/Welcome+to+Hell'
2998
    get_url_from_link = join_cls_url_to_href
2999
3000
    @classmethod
3001
    def get_first_comic_link(cls):
3002
        """Get link to first comics."""
3003
        return get_soup_at_url(cls.url).find('img', alt='First').parent
3004
3005
    @classmethod
3006
    def get_navi_link(cls, last_soup, next_):
3007
        """Get link to next or previous comic."""
3008
        img = last_soup.find('img', alt='Next' if next_ else 'Back')
3009
        return img.parent if img else None
3010
3011
    @classmethod
3012
    def get_comic_info(cls, soup, link):
3013
        """Get information about a particular comics."""
3014
        title = soup.find('meta', property='og:title')['content']
3015
        imgs = soup.find_all('meta', property='og:image')
3016
        return {
3017
            'title': title,
3018
            'img': [i['content'] for i in imgs],
3019
        }
3020
3021
3022
class SheldonComics(GenericNavigableComic):
3023
    """Class to retrieve Sheldon comics."""
3024
    # Also on http://www.gocomics.com/sheldon
3025
    name = 'sheldon'
3026
    long_name = 'Sheldon Comics'
3027
    url = 'http://www.sheldoncomics.com'
3028
3029
    @classmethod
3030
    def get_first_comic_link(cls):
3031
        """Get link to first comics."""
3032
        return get_soup_at_url(cls.url).find("a", id="nav-first")
3033
3034
    @classmethod
3035
    def get_navi_link(cls, last_soup, next_):
3036
        """Get link to next or previous comic."""
3037
        for link in last_soup.find_all("a", id="nav-next" if next_ else "nav-prev"):
3038
            if link['href'] != 'http://www.sheldoncomics.com':
3039
                return link
3040
        return None
3041
3042
    @classmethod
3043
    def get_comic_info(cls, soup, link):
3044
        """Get information about a particular comics."""
3045
        imgs = soup.find("div", id="comic-foot").find_all("img")
3046
        assert all(i['alt'] == i['title'] for i in imgs)
3047
        assert len(imgs) == 1
3048
        title = imgs[0]['title']
3049
        return {
3050
            'title': title,
3051
            'img': [i['src'] for i in imgs],
3052
        }
3053
3054
3055
class Ubertool(GenericNavigableComic):
3056
    """Class to retrieve Ubertool comics."""
3057
    # Also on http://ubertool.tumblr.com
3058
    # Also on https://tapastic.com/series/ubertool
3059
    name = 'ubertool'
3060
    long_name = 'Ubertool'
3061
    url = 'http://ubertoolcomic.com'
3062
    _categories = ('UBERTOOL', )
3063
    get_first_comic_link = get_a_comicnavbase_comicnavfirst
3064
    get_navi_link = get_a_comicnavbase_comicnavnext
3065
3066
    @classmethod
3067
    def get_comic_info(cls, soup, link):
3068
        """Get information about a particular comics."""
3069
        title = soup.find('h2', class_='post-title').string
3070
        date_str = soup.find('span', class_='post-date').string
3071
        day = string_to_date(date_str, "%B %d, %Y")
3072
        imgs = soup.find('div', id='comic').find_all('img')
3073
        return {
3074
            'img': [i['src'] for i in imgs],
3075
            'title': title,
3076
            'month': day.month,
3077
            'year': day.year,
3078
            'day': day.day,
3079
        }
3080
3081
3082
class EarthExplodes(GenericNavigableComic):
3083
    """Class to retrieve The Earth Explodes comics."""
3084
    name = 'earthexplodes'
3085
    long_name = 'The Earth Explodes'
3086
    url = 'http://www.earthexplodes.com'
3087
    get_url_from_link = join_cls_url_to_href
3088
    get_first_comic_link = simulate_first_link
3089
    first_url = 'http://www.earthexplodes.com/comics/000/'
3090
3091
    @classmethod
3092
    def get_navi_link(cls, last_soup, next_):
3093
        """Get link to next or previous comic."""
3094
        return last_soup.find('a', id='next' if next_ else 'prev')
3095
3096
    @classmethod
3097
    def get_comic_info(cls, soup, link):
3098
        """Get information about a particular comics."""
3099
        title = soup.find('title').string
3100
        imgs = soup.find('div', id='image').find_all('img')
3101
        alt = imgs[0].get('title', '')
3102
        return {
3103
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
3104
            'title': title,
3105
        }
3106
3107
3108
class CubeDrone(GenericNavigableComic):
3109
    """Class to retrieve Cube Drone comics."""
3110
    name = 'cubedrone'
3111
    long_name = 'Cube Drone'
3112
    url = 'http://cube-drone.com/comics'
3113
    get_url_from_link = join_cls_url_to_href
3114
3115
    @classmethod
3116
    def get_first_comic_link(cls):
3117
        """Get link to first comics."""
3118
        return get_soup_at_url(cls.url).find('span', class_='glyphicon glyphicon-backward').parent
3119
3120
    @classmethod
3121
    def get_navi_link(cls, last_soup, next_):
3122
        """Get link to next or previous comic."""
3123
        class_ = 'glyphicon glyphicon-chevron-' + ('right' if next_ else 'left')
3124 View Code Duplication
        return last_soup.find('span', class_=class_).parent
3125
3126
    @classmethod
3127
    def get_comic_info(cls, soup, link):
3128
        """Get information about a particular comics."""
3129
        title = soup.find('meta', attrs={'name': 'twitter:title'})['content']
3130
        url2 = soup.find('meta', attrs={'name': 'twitter:url'})['content']
3131
        # date_str = soup.find('h2', class_='comic_title').find('small').string
3132
        # day = string_to_date(date_str, "%B %d, %Y, %I:%M %p")
3133
        imgs = soup.find_all('img', class_='comic img-responsive')
3134
        title2 = imgs[0]['title']
3135
        alt = imgs[0]['alt']
3136
        return {
3137
            'url2': url2,
3138
            'title': title,
3139
            'title2': title2,
3140
            'alt': alt,
3141
            'img': [i['src'] for i in imgs],
3142
        }
3143
3144
3145
class MakeItStoopid(GenericNavigableComic):
3146
    """Class to retrieve Make It Stoopid Comics."""
3147
    name = 'stoopid'
3148
    long_name = 'Make it stoopid'
3149
    url = 'http://makeitstoopid.com/comic.php'
3150
3151
    @classmethod
3152
    def get_nav(cls, soup):
3153
        """Get the navigation elements from soup object."""
3154
        cnav = soup.find_all(class_='cnav')
3155
        nav1, nav2 = cnav[:5], cnav[5:]
3156
        assert nav1 == nav2
3157
        # begin, prev, archive, next_, end = nav1
3158
        return [None if i.get('href') is None else i for i in nav1]
3159
3160
    @classmethod
3161
    def get_first_comic_link(cls):
3162
        """Get link to first comics."""
3163
        return cls.get_nav(get_soup_at_url(cls.url))[0]
3164
3165
    @classmethod
3166
    def get_navi_link(cls, last_soup, next_):
3167
        """Get link to next or previous comic."""
3168
        return cls.get_nav(last_soup)[3 if next_ else 1]
3169
3170
    @classmethod
3171
    def get_comic_info(cls, soup, link):
3172
        """Get information about a particular comics."""
3173
        title = link['title']
3174
        imgs = soup.find_all('img', id='comicimg')
3175
        return {
3176
            'title': title,
3177
            'img': [i['src'] for i in imgs],
3178
        }
3179
3180
3181
class TuMourrasMoinsBete(GenericNavigableComic):
3182
    """Class to retrieve Tu Mourras Moins Bete comics."""
3183
    name = 'mourrasmoinsbete'
3184
    long_name = 'Tu Mourras Moins Bete'
3185
    url = 'http://tumourrasmoinsbete.blogspot.fr'
3186
    _categories = ('FRANCAIS', )
3187
    get_first_comic_link = simulate_first_link
3188
    first_url = 'http://tumourrasmoinsbete.blogspot.fr/2008/06/essai.html'
3189
3190
    @classmethod
3191 View Code Duplication
    def get_navi_link(cls, last_soup, next_):
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
3192
        """Get link to next or previous comic."""
3193
        return last_soup.find('a', id='Blog1_blog-pager-newer-link' if next_ else 'Blog1_blog-pager-older-link')
3194
3195
    @classmethod
3196
    def get_comic_info(cls, soup, link):
3197
        """Get information about a particular comics."""
3198
        title = soup.find('title').string
3199
        imgs = soup.find('div', itemprop='description articleBody').find_all('img')
3200
        author = soup.find('span', itemprop='author').string
3201
        return {
3202
            'img': [i['src'] for i in imgs],
3203
            'author': author,
3204
            'title': title,
3205
        }
3206
3207
3208
class GeekAndPoke(GenericNavigableComic):
3209
    """Class to retrieve Geek And Poke comics."""
3210
    name = 'geek'
3211
    long_name = 'Geek And Poke'
3212
    url = 'http://geek-and-poke.com'
3213
    get_url_from_link = join_cls_url_to_href
3214
    get_first_comic_link = simulate_first_link
3215
    first_url = 'http://geek-and-poke.com/geekandpoke/2006/8/27/a-new-place-for-a-not-so-old-blog.html'
3216
3217
    @classmethod
3218
    def get_navi_link(cls, last_soup, next_):
3219
        """Get link to next or previous comic."""
3220
        return last_soup.find('a', class_='prev-item' if next_ else 'next-item')
3221
3222
    @classmethod
3223
    def get_comic_info(cls, soup, link):
3224
        """Get information about a particular comics."""
3225
        title = soup.find('meta', property='og:title')['content']
3226
        desc = soup.find('meta', property='og:description')['content']
3227
        date_str = soup.find('time', class_='published')['datetime']
3228
        day = string_to_date(date_str, "%Y-%m-%d")
3229
        author = soup.find('a', rel='author').string
3230
        div_content = (soup.find('div', class_="body entry-content") or
3231
                       soup.find('div', class_="special-content"))
3232
        imgs = div_content.find_all('img')
3233
        imgs = [i for i in imgs if i.get('src') is not None]
3234
        assert all('title' not in i or i['alt'] == i['title'] for i in imgs)
3235
        alt = imgs[0].get('alt', "") if imgs else []
3236
        return {
3237
            'title': title,
3238
            'alt': alt,
3239
            'description': desc,
3240
            'author': author,
3241
            'day': day.day,
3242
            'month': day.month,
3243
            'year': day.year,
3244
            'img': [urljoin_wrapper(cls.url, i['src']) for i in imgs],
3245
        }
3246
3247
3248
class GloryOwlComix(GenericNavigableComic):
3249
    """Class to retrieve Glory Owl comics."""
3250
    name = 'gloryowl'
3251
    long_name = 'Glory Owl'
3252
    url = 'http://gloryowlcomix.blogspot.fr'
3253
    _categories = ('NSFW', 'FRANCAIS')
3254
    get_first_comic_link = simulate_first_link
3255
    first_url = 'http://gloryowlcomix.blogspot.fr/2013/02/1_7.html'
3256
3257
    @classmethod
3258
    def get_navi_link(cls, last_soup, next_):
3259
        """Get link to next or previous comic."""
3260
        return last_soup.find('a', id='Blog1_blog-pager-newer-link' if next_ else 'Blog1_blog-pager-older-link')
3261
3262
    @classmethod
3263
    def get_comic_info(cls, soup, link):
3264
        """Get information about a particular comics."""
3265
        title = soup.find('title').string
3266
        imgs = soup.find_all('link', rel='image_src')
3267
        author = soup.find('a', rel='author').string
3268
        return {
3269
            'img': [i['href'] for i in imgs],
3270
            'author': author,
3271
            'title': title,
3272
        }
3273
3274
3275
class GenericTumblrV1(GenericComic):
3276
    """Generic class to retrieve comics from Tumblr using the V1 API."""
3277
    _categories = ('TUMBLR', )
3278
3279
    @classmethod
3280
    def get_next_comic(cls, last_comic):
3281
        """Generic implementation of get_next_comic for Tumblr comics."""
3282
        for p in cls.get_posts(last_comic):
3283
            comic = cls.get_comic_info(p)
3284
            if comic is not None:
3285
                yield comic
3286
3287
    @classmethod
3288
    def get_url_from_post(cls, post):
3289
        return post['url']
3290
3291
    @classmethod
3292
    def get_api_url(cls):
3293
        return urljoin_wrapper(cls.url, '/api/read/')
3294
3295
    @classmethod
3296
    def get_comic_info(cls, post):
3297
        """Get information about a particular comics."""
3298
        type_ = post['type']
3299
        if type_ != 'photo':
3300
            return None
3301
        tumblr_id = int(post['id'])
3302
        api_url = cls.get_api_url() + '?id=%d' % (tumblr_id)
3303
        day = datetime.datetime.fromtimestamp(int(post['unix-timestamp'])).date()
3304
        caption = post.find('photo-caption')
3305
        title = caption.string if caption else ""
3306
        tags = ' '.join(t.string for t in post.find_all('tag'))
3307
        # Photos may appear in 'photo' tags and/or straight in the post
3308
        photo_tags = post.find_all('photo')
3309
        if not photo_tags:
3310
            photo_tags = [post]
3311
        # Images are in multiple resolutions - taking the first one
3312
        imgs = [photo.find('photo-url') for photo in photo_tags]
3313
        return {
3314
            'url': cls.get_url_from_post(post),
3315
            'url2': post['url-with-slug'],
3316
            'day': day.day,
3317
            'month': day.month,
3318
            'year': day.year,
3319
            'title': title,
3320
            'tags': tags,
3321
            'img': [i.string for i in imgs],
3322
            'tumblr-id': tumblr_id,
3323
            'api_url': api_url,
3324
        }
3325
3326
    @classmethod
3327
    def get_posts(cls, last_comic, nb_post_per_call=10):
3328
        """Get posts using API. nb_post_per_call is max 50.
3329
3330
        Posts are retrieved from newer to older as per the tumblr v1 api
3331
        but are returned in chronological order."""
3332
        waiting_for_url = last_comic['url'] if last_comic else None
3333
        posts_acc = []
3334
        if last_comic is not None:
3335
            # Sometimes, tumblr posts are deleted. When previous post is deleted, we
3336
            # might end up spending a lot of time looking for something that
3337
            # doesn't exist. Failing early and clearly might be a better option.
3338
            last_api_url = last_comic['api_url']
3339
            try:
3340
                get_soup_at_url(last_api_url)
3341
            except urllib.error.HTTPError:
3342
                try:
3343
                    get_soup_at_url(cls.url)
3344
                except urllib.error.HTTPError:
3345
                    print("Did not find previous post nor main url %s" % cls.url)
3346
                else:
3347
                    print("Did not find previous post %s : it might have been deleted" % last_api_url)
3348
                return reversed(posts_acc)
3349
        api_url = cls.get_api_url()
3350
        posts = get_soup_at_url(api_url).find('posts')
3351
        start, total = int(posts['start']), int(posts['total'])
3352
        assert start == 0
3353
        for starting_num in range(0, total, nb_post_per_call):
3354
            api_url2 = api_url + '?start=%d&num=%d' % (starting_num, nb_post_per_call)
3355
            posts2 = get_soup_at_url(api_url2).find('posts')
3356
            start2, total2 = int(posts2['start']), int(posts2['total'])
3357
            assert starting_num == start2, "%d != %d" % (starting_num, start2)
3358
            # This may happen and should be handled in the future
3359
            assert total == total2, "%d != %d" % (total, total2)
3360
            for p in posts2.find_all('post'):
3361
                if waiting_for_url and waiting_for_url == cls.get_url_from_post(p):
3362
                    return reversed(posts_acc)
3363
                posts_acc.append(p)
3364
        if waiting_for_url is None:
3365
            return reversed(posts_acc)
3366
        print("Did not find %s : there might be a problem" % waiting_for_url)
3367
        return []
3368
3369
3370
class SaturdayMorningBreakfastCerealTumblr(GenericTumblrV1):
3371
    """Class to retrieve Saturday Morning Breakfast Cereal comics."""
3372
    # Also on http://www.gocomics.com/saturday-morning-breakfast-cereal
3373
    # Also on http://www.smbc-comics.com
3374
    name = 'smbc-tumblr'
3375
    long_name = 'Saturday Morning Breakfast Cereal (from Tumblr)'
3376
    url = 'http://smbc-comics.tumblr.com'
3377
    _categories = ('SMBC', )
3378
3379
3380
class IrwinCardozo(GenericTumblrV1):
3381
    """Class to retrieve Irwin Cardozo Comics."""
3382
    name = 'irwinc'
3383
    long_name = 'Irwin Cardozo'
3384
    url = 'http://irwincardozocomics.tumblr.com'
3385
3386
3387
class AccordingToDevin(GenericTumblrV1):
3388
    """Class to retrieve According To Devin comics."""
3389
    name = 'devin'
3390
    long_name = 'According To Devin'
3391
    url = 'http://accordingtodevin.tumblr.com'
3392
3393
3394
class ItsTheTieTumblr(GenericTumblrV1):
3395
    """Class to retrieve It's the tie comics."""
3396
    # Also on http://itsthetie.com
3397
    # Also on https://tapastic.com/series/itsthetie
3398
    name = 'tie-tumblr'
3399
    long_name = "It's the tie (from Tumblr)"
3400
    url = "http://itsthetie.tumblr.com"
3401
    _categories = ('TIE', )
3402
3403
3404
class OctopunsTumblr(GenericTumblrV1):
3405
    """Class to retrieve Octopuns comics."""
3406
    # Also on http://www.octopuns.net
3407
    name = 'octopuns-tumblr'
3408
    long_name = 'Octopuns (from Tumblr)'
3409
    url = 'http://octopuns.tumblr.com'
3410
3411
3412
class PicturesInBoxesTumblr(GenericTumblrV1):
3413
    """Class to retrieve Pictures In Boxes comics."""
3414
    # Also on http://www.picturesinboxes.com
3415
    name = 'picturesinboxes-tumblr'
3416
    long_name = 'Pictures in Boxes (from Tumblr)'
3417
    url = 'http://picturesinboxescomic.tumblr.com'
3418
3419
3420
class TubeyToonsTumblr(GenericTumblrV1):
3421
    """Class to retrieve TubeyToons comics."""
3422
    # Also on http://tapastic.com/series/Tubey-Toons
3423
    # Also on http://tubeytoons.com
3424
    name = 'tubeytoons-tumblr'
3425
    long_name = 'Tubey Toons (from Tumblr)'
3426
    url = 'http://tubeytoons.tumblr.com'
3427
    _categories = ('TUNEYTOONS', )
3428
3429
3430
class UnearthedComicsTumblr(GenericTumblrV1):
3431
    """Class to retrieve Unearthed comics."""
3432
    # Also on http://tapastic.com/series/UnearthedComics
3433
    # Also on http://unearthedcomics.com
3434
    name = 'unearthed-tumblr'
3435
    long_name = 'Unearthed Comics (from Tumblr)'
3436
    url = 'http://unearthedcomics.tumblr.com'
3437
    _categories = ('UNEARTHED', )
3438
3439
3440
class PieComic(GenericTumblrV1):
3441
    """Class to retrieve Pie Comic comics."""
3442
    name = 'pie'
3443
    long_name = 'Pie Comic'
3444
    url = "http://piecomic.tumblr.com"
3445
3446
3447
class MrEthanDiamond(GenericTumblrV1):
3448
    """Class to retrieve Mr Ethan Diamond comics."""
3449
    name = 'diamond'
3450
    long_name = 'Mr Ethan Diamond'
3451
    url = 'http://mrethandiamond.tumblr.com'
3452
3453
3454
class Flocci(GenericTumblrV1):
3455
    """Class to retrieve floccinaucinihilipilification comics."""
3456
    name = 'flocci'
3457
    long_name = 'floccinaucinihilipilification'
3458
    url = "http://floccinaucinihilipilificationa.tumblr.com"
3459
3460
3461
class UpAndOut(GenericTumblrV1):
3462
    """Class to retrieve Up & Out comics."""
3463
    # Also on http://tapastic.com/series/UP-and-OUT
3464
    name = 'upandout'
3465
    long_name = 'Up And Out (from Tumblr)'
3466
    url = 'http://upandoutcomic.tumblr.com'
3467
3468
3469
class Pundemonium(GenericTumblrV1):
3470
    """Class to retrieve Pundemonium comics."""
3471
    name = 'pundemonium'
3472
    long_name = 'Pundemonium'
3473
    url = 'http://monstika.tumblr.com'
3474
3475
3476
class PoorlyDrawnLinesTumblr(GenericTumblrV1):
3477
    """Class to retrieve Poorly Drawn Lines comics."""
3478
    # Also on http://poorlydrawnlines.com
3479
    name = 'poorlydrawn-tumblr'
3480
    long_name = 'Poorly Drawn Lines (from Tumblr)'
3481
    url = 'http://pdlcomics.tumblr.com'
3482
    _categories = ('POORLYDRAWN', )
3483
3484
3485
class PearShapedComics(GenericTumblrV1):
3486
    """Class to retrieve Pear Shaped Comics."""
3487
    name = 'pearshaped'
3488
    long_name = 'Pear-Shaped Comics'
3489
    url = 'http://pearshapedcomics.com'
3490
3491
3492
class PondScumComics(GenericTumblrV1):
3493
    """Class to retrieve Pond Scum Comics."""
3494
    name = 'pond'
3495
    long_name = 'Pond Scum'
3496
    url = 'http://pondscumcomic.tumblr.com'
3497
3498
3499
class MercworksTumblr(GenericTumblrV1):
3500
    """Class to retrieve Mercworks comics."""
3501
    # Also on http://mercworks.net
3502
    name = 'mercworks-tumblr'
3503
    long_name = 'Mercworks (from Tumblr)'
3504
    url = 'http://mercworks.tumblr.com'
3505
3506
3507
class OwlTurdTumblr(GenericTumblrV1):
3508
    """Class to retrieve Owl Turd comics."""
3509
    # Also on http://tapastic.com/series/Owl-Turd-Comix
3510
    name = 'owlturd-tumblr'
3511
    long_name = 'Owl Turd (from Tumblr)'
3512
    url = 'http://owlturd.com'
3513
    _categories = ('OWLTURD', )
3514
3515
3516
class VectorBelly(GenericTumblrV1):
3517
    """Class to retrieve Vector Belly comics."""
3518
    # Also on http://vectorbelly.com
3519
    name = 'vector'
3520
    long_name = 'Vector Belly'
3521
    url = 'http://vectorbelly.tumblr.com'
3522
3523
3524
class GoneIntoRapture(GenericTumblrV1):
3525
    """Class to retrieve Gone Into Rapture comics."""
3526
    # Also on http://goneintorapture.tumblr.com
3527
    # Also on http://tapastic.com/series/Goneintorapture
3528
    name = 'rapture'
3529
    long_name = 'Gone Into Rapture'
3530
    url = 'http://www.goneintorapture.com'
3531
3532
3533
class TheOatmealTumblr(GenericTumblrV1):
3534
    """Class to retrieve The Oatmeal comics."""
3535
    # Also on http://theoatmeal.com
3536
    name = 'oatmeal-tumblr'
3537
    long_name = 'The Oatmeal (from Tumblr)'
3538
    url = 'http://oatmeal.tumblr.com'
3539
3540
3541
class HeckIfIKnowComicsTumblr(GenericTumblrV1):
3542
    """Class to retrieve Heck If I Know Comics."""
3543
    # Also on http://tapastic.com/series/Regular
3544
    name = 'heck-tumblr'
3545
    long_name = 'Heck if I Know comics (from Tumblr)'
3546
    url = 'http://heckifiknowcomics.com'
3547
3548
3549
class MyJetPack(GenericTumblrV1):
3550
    """Class to retrieve My Jet Pack comics."""
3551
    name = 'jetpack'
3552
    long_name = 'My Jet Pack'
3553
    url = 'http://myjetpack.tumblr.com'
3554
3555
3556
class CheerUpEmoKidTumblr(GenericTumblrV1):
3557
    """Class to retrieve CheerUpEmoKid comics."""
3558
    # Also on http://www.cheerupemokid.com
3559
    # Also on http://tapastic.com/series/CUEK
3560
    name = 'cuek-tumblr'
3561
    long_name = 'Cheer Up Emo Kid (from Tumblr)'
3562
    url = 'http://enzocomics.tumblr.com'
3563
3564
3565
class ForLackOfABetterComic(GenericTumblrV1):
3566
    """Class to retrieve For Lack Of A Better Comics."""
3567
    # Also on http://forlackofabettercomic.com
3568
    name = 'lack'
3569
    long_name = 'For Lack Of A Better Comic'
3570
    url = 'http://forlackofabettercomic.tumblr.com'
3571
3572
3573
class ZenPencilsTumblr(GenericTumblrV1):
3574
    """Class to retrieve ZenPencils comics."""
3575
    # Also on http://zenpencils.com
3576
    # Also on http://www.gocomics.com/zen-pencils
3577
    name = 'zenpencils-tumblr'
3578
    long_name = 'Zen Pencils (from Tumblr)'
3579
    url = 'http://zenpencils.tumblr.com'
3580
    _categories = ('ZENPENCILS', )
3581
3582
3583
class ThreeWordPhraseTumblr(GenericTumblrV1):
3584
    """Class to retrieve Three Word Phrase comics."""
3585
    # Also on http://threewordphrase.com
3586
    name = 'threeword-tumblr'
3587
    long_name = 'Three Word Phrase (from Tumblr)'
3588
    url = 'http://www.threewordphrase.tumblr.com'
3589
3590
3591
class TimeTrabbleTumblr(GenericTumblrV1):
3592
    """Class to retrieve Time Trabble comics."""
3593
    # Also on http://timetrabble.com
3594
    name = 'timetrabble-tumblr'
3595
    long_name = 'Time Trabble (from Tumblr)'
3596
    url = 'http://timetrabble.tumblr.com'
3597
3598
3599
class SafelyEndangeredTumblr(GenericTumblrV1):
3600
    """Class to retrieve Safely Endangered comics."""
3601
    # Also on http://www.safelyendangered.com
3602
    name = 'endangered-tumblr'
3603
    long_name = 'Safely Endangered (from Tumblr)'
3604
    url = 'http://tumblr.safelyendangered.com'
3605
3606
3607
class MouseBearComedyTumblr(GenericTumblrV1):
3608
    """Class to retrieve Mouse Bear Comedy comics."""
3609
    # Also on http://www.mousebearcomedy.com
3610
    name = 'mousebear-tumblr'
3611
    long_name = 'Mouse Bear Comedy (from Tumblr)'
3612
    url = 'http://mousebearcomedy.tumblr.com'
3613
3614
3615
class BouletCorpTumblr(GenericTumblrV1):
3616
    """Class to retrieve BouletCorp comics."""
3617
    # Also on http://www.bouletcorp.com
3618
    name = 'boulet-tumblr'
3619
    long_name = 'Boulet Corp (from Tumblr)'
3620
    url = 'http://bouletcorp.tumblr.com'
3621
    _categories = ('BOULET', )
3622
3623
3624
class TheAwkwardYetiTumblr(GenericTumblrV1):
3625
    """Class to retrieve The Awkward Yeti comics."""
3626
    # Also on http://www.gocomics.com/the-awkward-yeti
3627
    # Also on http://theawkwardyeti.com
3628
    # Also on https://tapastic.com/series/TheAwkwardYeti
3629
    name = 'yeti-tumblr'
3630
    long_name = 'The Awkward Yeti (from Tumblr)'
3631
    url = 'http://larstheyeti.tumblr.com'
3632
    _categories = ('YETI', )
3633
3634
3635
class NellucNhoj(GenericTumblrV1):
3636
    """Class to retrieve NellucNhoj comics."""
3637
    name = 'nhoj'
3638
    long_name = 'Nelluc Nhoj'
3639
    url = 'http://nellucnhoj.com'
3640
3641
3642
class DownTheUpwardSpiralTumblr(GenericTumblrV1):
3643
    """Class to retrieve Down The Upward Spiral comics."""
3644
    # Also on http://www.downtheupwardspiral.com
3645
    name = 'spiral-tumblr'
3646
    long_name = 'Down the Upward Spiral (from Tumblr)'
3647
    url = 'http://downtheupwardspiral.tumblr.com'
3648
3649
3650
class AsPerUsualTumblr(GenericTumblrV1):
3651
    """Class to retrieve As Per Usual comics."""
3652
    # Also on https://tapastic.com/series/AsPerUsual
3653
    name = 'usual-tumblr'
3654
    long_name = 'As Per Usual (from Tumblr)'
3655
    url = 'http://as-per-usual.tumblr.com'
3656
    categories = ('DAMILEE', )
3657
3658
3659
class HotComicsForCoolPeopleTumblr(GenericTumblrV1):
3660
    """Class to retrieve Hot Comics For Cool People."""
3661
    # Also on https://tapastic.com/series/Hot-Comics-For-Cool-People
3662
    # Also on http://hotcomics.biz (links to tumblr)
3663
    # Also on http://hcfcp.com (links to tumblr)
3664
    name = 'hotcomics-tumblr'
3665
    long_name = 'Hot Comics For Cool People (from Tumblr)'
3666
    url = 'http://hotcomicsforcoolpeople.tumblr.com'
3667
    categories = ('DAMILEE', )
3668
3669
3670
class OneOneOneOneComicTumblr(GenericTumblrV1):
3671
    """Class to retrieve 1111 Comics."""
3672
    # Also on http://www.1111comics.me
3673
    # Also on https://tapastic.com/series/1111-Comics
3674
    name = '1111-tumblr'
3675
    long_name = '1111 Comics (from Tumblr)'
3676
    url = 'http://comics1111.tumblr.com'
3677
    _categories = ('ONEONEONEONE', )
3678
3679
3680
class JhallComicsTumblr(GenericTumblrV1):
3681
    """Class to retrieve Jhall Comics."""
3682
    # Also on http://jhallcomics.com
3683
    name = 'jhall-tumblr'
3684
    long_name = 'Jhall Comics (from Tumblr)'
3685
    url = 'http://jhallcomics.tumblr.com'
3686
3687
3688
class BerkeleyMewsTumblr(GenericTumblrV1):
3689
    """Class to retrieve Berkeley Mews comics."""
3690
    # Also on http://www.gocomics.com/berkeley-mews
3691
    # Also on http://www.berkeleymews.com
3692
    name = 'berkeley-tumblr'
3693
    long_name = 'Berkeley Mews (from Tumblr)'
3694
    url = 'http://mews.tumblr.com'
3695
    _categories = ('BERKELEY', )
3696
3697
3698
class JoanCornellaTumblr(GenericTumblrV1):
3699
    """Class to retrieve Joan Cornella comics."""
3700
    # Also on http://joancornella.net
3701
    name = 'cornella-tumblr'
3702
    long_name = 'Joan Cornella (from Tumblr)'
3703
    url = 'http://cornellajoan.tumblr.com'
3704
3705
3706
class RespawnComicTumblr(GenericTumblrV1):
3707
    """Class to retrieve Respawn Comic."""
3708
    # Also on http://respawncomic.com
3709
    name = 'respawn-tumblr'
3710
    long_name = 'Respawn Comic (from Tumblr)'
3711
    url = 'http://respawncomic.tumblr.com'
3712
3713
3714
class ChrisHallbeckTumblr(GenericTumblrV1):
3715
    """Class to retrieve Chris Hallbeck comics."""
3716
    # Also on https://tapastic.com/ChrisHallbeck
3717
    # Also on http://maximumble.com
3718
    # Also on http://minimumble.com
3719
    # Also on http://thebookofbiff.com
3720
    name = 'hallbeck-tumblr'
3721
    long_name = 'Chris Hallback (from Tumblr)'
3722
    url = 'http://chrishallbeck.tumblr.com'
3723
    _categories = ('HALLBACK', )
3724
3725
3726
class ComicNuggets(GenericTumblrV1):
3727
    """Class to retrieve Comic Nuggets."""
3728
    name = 'nuggets'
3729
    long_name = 'Comic Nuggets'
3730
    url = 'http://comicnuggets.com'
3731
3732
3733
class PigeonGazetteTumblr(GenericTumblrV1):
3734
    """Class to retrieve The Pigeon Gazette comics."""
3735
    # Also on https://tapastic.com/series/The-Pigeon-Gazette
3736
    name = 'pigeon-tumblr'
3737
    long_name = 'The Pigeon Gazette (from Tumblr)'
3738
    url = 'http://thepigeongazette.tumblr.com'
3739
3740
3741
class CancerOwl(GenericTumblrV1):
3742
    """Class to retrieve Cancer Owl comics."""
3743
    # Also on http://cancerowl.com
3744
    name = 'cancerowl-tumblr'
3745
    long_name = 'Cancer Owl (from Tumblr)'
3746
    url = 'http://cancerowl.tumblr.com'
3747
3748
3749
class FowlLanguageTumblr(GenericTumblrV1):
3750
    """Class to retrieve Fowl Language comics."""
3751
    # Also on http://www.fowllanguagecomics.com
3752
    # Also on http://tapastic.com/series/Fowl-Language-Comics
3753
    # Also on http://www.gocomics.com/fowl-language
3754
    name = 'fowllanguage-tumblr'
3755
    long_name = 'Fowl Language Comics (from Tumblr)'
3756
    url = 'http://fowllanguagecomics.tumblr.com'
3757
    _categories = ('FOWLLANGUAGE', )
3758
3759
3760
class TheOdd1sOutTumblr(GenericTumblrV1):
3761
    """Class to retrieve The Odd 1s Out comics."""
3762
    # Also on http://theodd1sout.com
3763
    # Also on https://tapastic.com/series/Theodd1sout
3764
    name = 'theodd-tumblr'
3765
    long_name = 'The Odd 1s Out (from Tumblr)'
3766
    url = 'http://theodd1sout.tumblr.com'
3767
3768
3769
class TheUnderfoldTumblr(GenericTumblrV1):
3770
    """Class to retrieve The Underfold comics."""
3771
    # Also on http://theunderfold.com
3772
    name = 'underfold-tumblr'
3773
    long_name = 'The Underfold (from Tumblr)'
3774
    url = 'http://theunderfold.tumblr.com'
3775
3776
3777
class LolNeinTumblr(GenericTumblrV1):
3778
    """Class to retrieve Lol Nein comics."""
3779
    # Also on http://lolnein.com
3780
    name = 'lolnein-tumblr'
3781
    long_name = 'Lol Nein (from Tumblr)'
3782
    url = 'http://lolneincom.tumblr.com'
3783
3784
3785
class FatAwesomeComicsTumblr(GenericTumblrV1):
3786
    """Class to retrieve Fat Awesome Comics."""
3787
    # Also on http://fatawesome.com/comics
3788
    name = 'fatawesome-tumblr'
3789
    long_name = 'Fat Awesome (from Tumblr)'
3790
    url = 'http://fatawesomecomedy.tumblr.com'
3791
3792
3793
class TheWorldIsFlatTumblr(GenericTumblrV1):
3794
    """Class to retrieve The World Is Flat Comics."""
3795
    # Also on https://tapastic.com/series/The-World-is-Flat
3796
    name = 'flatworld-tumblr'
3797
    long_name = 'The World Is Flat (from Tumblr)'
3798
    url = 'http://theworldisflatcomics.tumblr.com'
3799
3800
3801
class DorrisMc(GenericTumblrV1):
3802
    """Class to retrieve Dorris Mc Comics"""
3803
    # Also on http://www.gocomics.com/dorris-mccomics
3804
    name = 'dorrismc'
3805
    long_name = 'Dorris Mc'
3806
    url = 'http://dorrismccomics.com'
3807
3808
3809
class LeleozTumblr(GenericEmptyComic, GenericTumblrV1):
3810
    """Class to retrieve Leleoz comics."""
3811
    # Also on https://tapastic.com/series/Leleoz
3812
    name = 'leleoz-tumblr'
3813
    long_name = 'Leleoz (from Tumblr)'
3814
    url = 'http://leleozcomics.tumblr.com'
3815
3816
3817
class MoonBeardTumblr(GenericTumblrV1):
3818
    """Class to retrieve MoonBeard comics."""
3819
    # Also on http://moonbeard.com
3820
    # Also on http://www.webtoons.com/en/comedy/moon-beard/list?title_no=471
3821
    name = 'moonbeard-tumblr'
3822
    long_name = 'Moon Beard (from Tumblr)'
3823
    url = 'http://blog.squiresjam.es/moonbeard'
3824
3825
3826
class AComik(GenericTumblrV1):
3827
    """Class to retrieve A Comik"""
3828
    name = 'comik'
3829
    long_name = 'A Comik'
3830
    url = 'http://acomik.com'
3831
3832
3833
class ClassicRandy(GenericTumblrV1):
3834
    """Class to retrieve Classic Randy comics."""
3835
    name = 'randy'
3836
    long_name = 'Classic Randy'
3837
    url = 'http://classicrandy.tumblr.com'
3838
3839
3840
class DagssonTumblr(GenericTumblrV1):
3841
    """Class to retrieve Dagsson comics."""
3842
    # Also on http://www.dagsson.com
3843
    name = 'dagsson-tumblr'
3844
    long_name = 'Dagsson Hugleikur (from Tumblr)'
3845
    url = 'http://hugleikurdagsson.tumblr.com'
3846
3847
3848
class LinsEditionsTumblr(GenericTumblrV1):
3849
    """Class to retrieve L.I.N.S. Editions comics."""
3850
    # Also on https://linsedition.com
3851
    name = 'lins-tumblr'
3852
    long_name = 'L.I.N.S. Editions (from Tumblr)'
3853
    url = 'http://linscomics.tumblr.com'
3854
    _categories = ('LINS', )
3855
3856
3857
class OrigamiHotDish(GenericTumblrV1):
3858
    """Class to retrieve Origami Hot Dish comics."""
3859
    name = 'origamihotdish'
3860
    long_name = 'Origami Hot Dish'
3861
    url = 'http://origamihotdish.com'
3862
3863
3864
class HitAndMissComicsTumblr(GenericTumblrV1):
3865
    """Class to retrieve Hit and Miss Comics."""
3866
    name = 'hitandmiss'
3867
    long_name = 'Hit and Miss Comics'
3868
    url = 'http://hitandmisscomics.tumblr.com'
3869
3870
3871
class HMBlanc(GenericTumblrV1):
3872
    """Class to retrieve HM Blanc comics."""
3873
    name = 'hmblanc'
3874
    long_name = 'HM Blanc'
3875
    url = 'http://hmblanc.tumblr.com'
3876
3877
3878
class TalesOfAbsurdityTumblr(GenericTumblrV1):
3879
    """Class to retrieve Tales Of Absurdity comics."""
3880
    # Also on http://talesofabsurdity.com
3881
    # Also on http://tapastic.com/series/Tales-Of-Absurdity
3882
    name = 'absurdity-tumblr'
3883
    long_name = 'Tales of Absurdity (from Tumblr)'
3884
    url = 'http://talesofabsurdity.tumblr.com'
3885
    _categories = ('ABSURDITY', )
3886
3887
3888
class RobbieAndBobby(GenericTumblrV1):
3889
    """Class to retrieve Robbie And Bobby comics."""
3890
    # Also on http://robbieandbobby.com
3891
    name = 'robbie-tumblr'
3892
    long_name = 'Robbie And Bobby (from Tumblr)'
3893
    url = 'http://robbieandbobby.tumblr.com'
3894
3895
3896
class ElectricBunnyComicTumblr(GenericTumblrV1):
3897
    """Class to retrieve Electric Bunny Comics."""
3898
    # Also on http://www.electricbunnycomics.com/View/Comic/153/Welcome+to+Hell
3899
    name = 'bunny-tumblr'
3900
    long_name = 'Electric Bunny Comic (from Tumblr)'
3901
    url = 'http://electricbunnycomics.tumblr.com'
3902
3903
3904
class Hoomph(GenericTumblrV1):
3905
    """Class to retrieve Hoomph comics."""
3906
    name = 'hoomph'
3907
    long_name = 'Hoomph'
3908
    url = 'http://hoom.ph'
3909
3910
3911
class BFGFSTumblr(GenericTumblrV1):
3912
    """Class to retrieve BFGFS comics."""
3913
    # Also on https://tapastic.com/series/BFGFS
3914
    # Also on http://bfgfs.com
3915
    name = 'bfgfs-tumblr'
3916
    long_name = 'BFGFS (from Tumblr)'
3917
    url = 'http://bfgfs.tumblr.com'
3918
3919
3920
class DoodleForFood(GenericTumblrV1):
3921
    """Class to retrieve Doodle For Food comics."""
3922
    # Also on http://doodleforfood.com
3923
    name = 'doodle'
3924
    long_name = 'Doodle For Food'
3925
    url = 'http://doodleforfood.com'
3926
3927
3928
class CassandraCalinTumblr(GenericTumblrV1):
3929
    """Class to retrieve C. Cassandra comics."""
3930
    # Also on http://cassandracalin.com
3931
    # Also on https://tapastic.com/series/C-Cassandra-comics
3932
    name = 'cassandra-tumblr'
3933
    long_name = 'Cassandra Calin (from Tumblr)'
3934
    url = 'http://c-cassandra.tumblr.com'
3935
3936
3937
class DougWasTaken(GenericTumblrV1):
3938
    """Class to retrieve Doug Was Taken comics."""
3939
    name = 'doug'
3940
    long_name = 'Doug Was Taken'
3941
    url = 'http://dougwastaken.tumblr.com'
3942
3943
3944
class MandatoryRollerCoaster(GenericTumblrV1):
3945
    """Class to retrieve Mandatory Roller Coaster comics."""
3946
    name = 'rollercoaster'
3947
    long_name = 'Mandatory Roller Coaster'
3948
    url = 'http://mandatoryrollercoaster.com'
3949
3950
3951
class CEstPasEnRegardantSesPompes(GenericTumblrV1):
3952
    """Class to retrieve C'Est Pas En Regardant Ses Pompes (...)  comics."""
3953
    name = 'cperspqccltt'
3954
    long_name = 'C Est Pas En Regardant Ses Pompes (...)'
3955
    url = 'http://cperspqccltt.tumblr.com'
3956
3957
3958
class TheGrohlTroll(GenericTumblrV1):
3959
    """Class to retrieve The Grohl Troll comics."""
3960
    name = 'grohltroll'
3961
    long_name = 'The Grohl Troll'
3962
    url = 'http://thegrohltroll.com'
3963
3964
3965
class WebcomicName(GenericTumblrV1):
3966
    """Class to retrieve Webcomic Name comics."""
3967
    name = 'webcomicname'
3968
    long_name = 'Webcomic Name'
3969
    url = 'http://webcomicname.com'
3970
3971
3972
class BooksOfAdam(GenericTumblrV1):
3973
    """Class to retrieve Books of Adam comics."""
3974
    # Also on http://www.booksofadam.com
3975
    name = 'booksofadam'
3976
    long_name = 'Books of Adam'
3977
    url = 'http://booksofadam.tumblr.com'
3978
3979
3980
class HarkAVagrant(GenericTumblrV1):
3981
    """Class to retrieve Hark A Vagrant comics."""
3982
    # Also on http://www.harkavagrant.com
3983
    name = 'hark-tumblr'
3984
    long_name = 'Hark A Vagrant (from Tumblr)'
3985
    url = 'http://beatonna.tumblr.com'
3986
3987
3988
class OurSuperAdventureTumblr(GenericTumblrV1):
3989
    """Class to retrieve Our Super Adventure comics."""
3990
    # Also on https://tapastic.com/series/Our-Super-Adventure
3991
    # Also on http://www.oursuperadventure.com
3992
    # http://sarahgraley.com
3993
    name = 'superadventure-tumblr'
3994
    long_name = 'Our Super Adventure (from Tumblr)'
3995
    url = 'http://sarahssketchbook.tumblr.com'
3996
3997
3998
class JakeLikesOnions(GenericTumblrV1):
3999
    """Class to retrieve Jake Likes Onions comics."""
4000
    name = 'jake'
4001
    long_name = 'Jake Likes Onions'
4002
    url = 'http://jakelikesonions.com'
4003
4004
4005
class InYourFaceCake(GenericTumblrV1):
4006
    """Class to retrieve In Your Face Cake comics."""
4007
    name = 'inyourfacecake-tumblr'
4008
    long_name = 'In Your Face Cake (from Tumblr)'
4009
    url = 'http://in-your-face-cake.tumblr.com'
4010
4011
4012
class Robospunk(GenericTumblrV1):
4013
    """Class to retrieve Robospunk comics."""
4014
    name = 'robospunk'
4015
    long_name = 'Robospunk'
4016
    url = 'http://robospunk.com'
4017
4018
4019
class BananaTwinky(GenericTumblrV1):
4020
    """Class to retrieve Banana Twinky comics."""
4021
    name = 'banana'
4022
    long_name = 'Banana Twinky'
4023
    url = 'http://bananatwinky.tumblr.com'
4024
4025
4026
class YesterdaysPopcornTumblr(GenericTumblrV1):
4027
    """Class to retrieve Yesterday's Popcorn comics."""
4028
    # Also on http://www.yesterdayspopcorn.com
4029
    # Also on https://tapastic.com/series/Yesterdays-Popcorn
4030
    name = 'popcorn-tumblr'
4031
    long_name = 'Yesterday\'s Popcorn (from Tumblr)'
4032
    url = 'http://yesterdayspopcorn.tumblr.com'
4033
4034
4035
class TwistedDoodles(GenericTumblrV1):
4036
    """Class to retrieve Twisted Doodles comics."""
4037
    name = 'twisted'
4038
    long_name = 'Twisted Doodles'
4039
    url = 'http://www.twisteddoodles.com'
4040
4041
4042
class UbertoolTumblr(GenericTumblrV1):
4043
    """Class to retrieve Ubertool comics."""
4044
    # Also on http://ubertoolcomic.com
4045
    # Also on https://tapastic.com/series/ubertool
4046
    name = 'ubertool-tumblr'
4047
    long_name = 'Ubertool (from Tumblr)'
4048
    url = 'http://ubertool.tumblr.com'
4049
    _categories = ('UBERTOOL', )
4050
4051
4052
class LittleLifeLinesTumblr(GenericTumblrV1):
4053
    """Class to retrieve Little Life Lines comics."""
4054
    # Also on http://www.littlelifelines.com
4055
    name = 'life-tumblr'
4056
    long_name = 'Little Life Lines (from Tumblr)'
4057
    url = 'https://little-life-lines.tumblr.com'
4058
4059
4060
class TheyCanTalk(GenericTumblrV1):
4061
    """Class to retrieve They Can Talk comics."""
4062
    name = 'theycantalk'
4063
    long_name = 'They Can Talk'
4064
    url = 'http://theycantalk.com'
4065
4066
4067
class Will5NeverCome(GenericTumblrV1):
4068
    """Class to retrieve Will 5:00 Never Come comics."""
4069
    name = 'will5'
4070
    long_name = 'Will 5:00 Never Come ?'
4071
    url = 'http://will5nevercome.com'
4072
4073
4074
class Sephko(GenericTumblrV1):
4075
    """Class to retrieve Sephko Comics."""
4076
    # Also on http://www.sephko.com
4077
    name = 'sephko'
4078
    long_name = 'Sephko'
4079
    url = 'http://sephko.tumblr.com'
4080
4081
4082
class BlazersAtDawn(GenericTumblrV1):
4083
    """Class to retrieve Blazers At Dawn Comics."""
4084
    name = 'blazers'
4085
    long_name = 'Blazers At Dawn'
4086
    url = 'http://blazersatdawn.tumblr.com'
4087
4088
4089
class ArtByMoga(GenericEmptyComic, GenericTumblrV1):  # Deactivated because it downloads too many things
4090
    """Class to retrieve Art By Moga Comics."""
4091
    name = 'moga'
4092
    long_name = 'Art By Moga'
4093
    url = 'http://artbymoga.tumblr.com'
4094
4095
4096
class HorovitzComics(GenericListableComic):
4097
    """Generic class to handle the logic common to the different comics from Horovitz."""
4098
    url = 'http://www.horovitzcomics.com'
4099
    _categories = ('HOROVITZ', )
4100
    img_re = re.compile('.*comics/([0-9]*)/([0-9]*)/([0-9]*)/.*$')
4101
    link_re = NotImplemented
4102
    get_url_from_archive_element = join_cls_url_to_href
4103
4104
    @classmethod
4105
    def get_comic_info(cls, soup, link):
4106
        """Get information about a particular comics."""
4107
        href = link['href']
4108
        num = int(cls.link_re.match(href).groups()[0])
4109
        title = link.string
4110
        imgs = soup.find_all('img', id='comic')
4111
        assert len(imgs) == 1
4112
        year, month, day = [int(s)
4113
                            for s in cls.img_re.match(imgs[0]['src']).groups()]
4114
        return {
4115
            'title': title,
4116
            'day': day,
4117
            'month': month,
4118
            'year': year,
4119
            'img': [i['src'] for i in imgs],
4120
            'num': num,
4121
        }
4122
4123
    @classmethod
4124
    def get_archive_elements(cls):
4125
        archive_url = 'http://www.horovitzcomics.com/comics/archive/'
4126
        return reversed(get_soup_at_url(archive_url).find_all('a', href=cls.link_re))
4127
4128
4129
class HorovitzNew(HorovitzComics):
4130
    """Class to retrieve Horovitz new comics."""
4131
    name = 'horovitznew'
4132
    long_name = 'Horovitz New'
4133
    link_re = re.compile('^/comics/new/([0-9]+)$')
4134
4135
4136
class HorovitzClassic(HorovitzComics):
4137
    """Class to retrieve Horovitz classic comics."""
4138
    name = 'horovitzclassic'
4139
    long_name = 'Horovitz Classic'
4140
    link_re = re.compile('^/comics/classic/([0-9]+)$')
4141
4142
4143
class GenericGoComic(GenericNavigableComic):
4144
    """Generic class to handle the logic common to comics from gocomics.com."""
4145
    _categories = ('GOCOMIC', )
4146
    url_date_re = re.compile('.*/([0-9]*)/([0-9]*)/([0-9]*)$')
4147
4148
    @classmethod
4149
    def get_first_comic_link(cls):
4150
        """Get link to first comics."""
4151
        return get_soup_at_url(cls.url).find('a', class_='beginning')
4152
4153
    @classmethod
4154
    def get_navi_link(cls, last_soup, next_):
4155
        """Get link to next or previous comic."""
4156
        return last_soup.find('a', class_='next' if next_ else 'prev', href=cls.url_date_re)
4157
4158
    @classmethod
4159
    def get_url_from_link(cls, link):
4160
        gocomics = 'http://www.gocomics.com'
4161
        return urljoin_wrapper(gocomics, link['href'])
4162
4163
    @classmethod
4164
    def get_comic_info(cls, soup, link):
4165
        """Get information about a particular comics."""
4166
        url = cls.get_url_from_link(link)
4167
        year, month, day = [int(s)
4168
                            for s in cls.url_date_re.match(url).groups()]
4169
        return {
4170
            'day': day,
4171
            'month': month,
4172
            'year': year,
4173
            'img': [soup.find_all('img', class_='strip')[-1]['src']],
4174
            'author': soup.find('meta', attrs={'name': 'author'})['content']
4175
        }
4176
4177
4178
class PearlsBeforeSwine(GenericGoComic):
4179
    """Class to retrieve Pearls Before Swine comics."""
4180
    name = 'pearls'
4181
    long_name = 'Pearls Before Swine'
4182
    url = 'http://www.gocomics.com/pearlsbeforeswine'
4183
4184
4185
class Peanuts(GenericGoComic):
4186
    """Class to retrieve Peanuts comics."""
4187
    name = 'peanuts'
4188
    long_name = 'Peanuts'
4189
    url = 'http://www.gocomics.com/peanuts'
4190
4191
4192
class MattWuerker(GenericGoComic):
4193
    """Class to retrieve Matt Wuerker comics."""
4194
    name = 'wuerker'
4195
    long_name = 'Matt Wuerker'
4196
    url = 'http://www.gocomics.com/mattwuerker'
4197
4198
4199
class TomToles(GenericGoComic):
4200
    """Class to retrieve Tom Toles comics."""
4201
    name = 'toles'
4202
    long_name = 'Tom Toles'
4203
    url = 'http://www.gocomics.com/tomtoles'
4204
4205
4206
class BreakOfDay(GenericGoComic):
4207
    """Class to retrieve Break Of Day comics."""
4208
    name = 'breakofday'
4209
    long_name = 'Break Of Day'
4210
    url = 'http://www.gocomics.com/break-of-day'
4211
4212
4213
class Brevity(GenericGoComic):
4214
    """Class to retrieve Brevity comics."""
4215
    name = 'brevity'
4216
    long_name = 'Brevity'
4217
    url = 'http://www.gocomics.com/brevity'
4218
4219
4220
class MichaelRamirez(GenericGoComic):
4221
    """Class to retrieve Michael Ramirez comics."""
4222
    name = 'ramirez'
4223
    long_name = 'Michael Ramirez'
4224
    url = 'http://www.gocomics.com/michaelramirez'
4225
4226
4227
class MikeLuckovich(GenericGoComic):
4228
    """Class to retrieve Mike Luckovich comics."""
4229
    name = 'luckovich'
4230
    long_name = 'Mike Luckovich'
4231
    url = 'http://www.gocomics.com/mikeluckovich'
4232
4233
4234
class JimBenton(GenericGoComic):
4235
    """Class to retrieve Jim Benton comics."""
4236
    # Also on http://jimbenton.tumblr.com
4237
    name = 'benton'
4238
    long_name = 'Jim Benton'
4239
    url = 'http://www.gocomics.com/jim-benton-cartoons'
4240
4241
4242
class TheArgyleSweater(GenericGoComic):
4243
    """Class to retrieve the Argyle Sweater comics."""
4244
    name = 'argyle'
4245
    long_name = 'Argyle Sweater'
4246
    url = 'http://www.gocomics.com/theargylesweater'
4247
4248
4249
class SunnyStreet(GenericGoComic):
4250
    """Class to retrieve Sunny Street comics."""
4251
    # Also on http://www.sunnystreetcomics.com
4252
    name = 'sunny'
4253
    long_name = 'Sunny Street'
4254
    url = 'http://www.gocomics.com/sunny-street'
4255
4256
4257
class OffTheMark(GenericGoComic):
4258
    """Class to retrieve Off The Mark comics."""
4259
    # Also on https://www.offthemark.com
4260
    name = 'offthemark'
4261
    long_name = 'Off The Mark'
4262
    url = 'http://www.gocomics.com/offthemark'
4263
4264
4265
class WuMo(GenericGoComic):
4266
    """Class to retrieve WuMo comics."""
4267
    # Also on http://wumo.com
4268
    name = 'wumo'
4269
    long_name = 'WuMo'
4270
    url = 'http://www.gocomics.com/wumo'
4271
4272
4273
class LunarBaboon(GenericGoComic):
4274
    """Class to retrieve Lunar Baboon comics."""
4275
    # Also on http://www.lunarbaboon.com
4276
    # Also on https://tapastic.com/series/Lunarbaboon
4277
    name = 'lunarbaboon'
4278
    long_name = 'Lunar Baboon'
4279
    url = 'http://www.gocomics.com/lunarbaboon'
4280
4281
4282
class SandersenGocomic(GenericGoComic):
4283
    """Class to retrieve Sarah Andersen comics."""
4284
    # Also on http://sarahcandersen.com
4285
    # Also on http://tapastic.com/series/Doodle-Time
4286
    name = 'sandersen-goc'
4287
    long_name = 'Sarah Andersen (from GoComics)'
4288
    url = 'http://www.gocomics.com/sarahs-scribbles'
4289
4290
4291
class SaturdayMorningBreakfastCerealGoComic(GenericGoComic):
4292
    """Class to retrieve Saturday Morning Breakfast Cereal comics."""
4293
    # Also on http://smbc-comics.tumblr.com
4294
    # Also on http://www.smbc-comics.com
4295
    name = 'smbc-goc'
4296
    long_name = 'Saturday Morning Breakfast Cereal (from GoComics)'
4297
    url = 'http://www.gocomics.com/saturday-morning-breakfast-cereal'
4298
    _categories = ('SMBC', )
4299
4300
4301
class CalvinAndHobbesGoComic(GenericGoComic):
4302
    """Class to retrieve Calvin and Hobbes comics."""
4303
    # From gocomics, not http://marcel-oehler.marcellosendos.ch/comics/ch/
4304
    name = 'calvin-goc'
4305
    long_name = 'Calvin and Hobbes (from GoComics)'
4306
    url = 'http://www.gocomics.com/calvinandhobbes'
4307
4308
4309
class RallGoComic(GenericGoComic):
4310
    """Class to retrieve Ted Rall comics."""
4311
    # Also on http://rall.com/comic
4312
    name = 'rall-goc'
4313
    long_name = "Ted Rall (from GoComics)"
4314
    url = "http://www.gocomics.com/tedrall"
4315
    _categories = ('RALL', )
4316
4317
4318
class TheAwkwardYetiGoComic(GenericGoComic):
4319
    """Class to retrieve The Awkward Yeti comics."""
4320
    # Also on http://larstheyeti.tumblr.com
4321
    # Also on http://theawkwardyeti.com
4322
    # Also on https://tapastic.com/series/TheAwkwardYeti
4323
    name = 'yeti-goc'
4324
    long_name = 'The Awkward Yeti (from GoComics)'
4325
    url = 'http://www.gocomics.com/the-awkward-yeti'
4326
    _categories = ('YETI', )
4327
4328
4329
class BerkeleyMewsGoComics(GenericGoComic):
4330
    """Class to retrieve Berkeley Mews comics."""
4331
    # Also on http://mews.tumblr.com
4332
    # Also on http://www.berkeleymews.com
4333
    name = 'berkeley-goc'
4334
    long_name = 'Berkeley Mews (from GoComics)'
4335
    url = 'http://www.gocomics.com/berkeley-mews'
4336
    _categories = ('BERKELEY', )
4337
4338
4339
class SheldonGoComics(GenericGoComic):
4340
    """Class to retrieve Sheldon comics."""
4341
    # Also on http://www.sheldoncomics.com
4342
    name = 'sheldon-goc'
4343
    long_name = 'Sheldon Comics (from GoComics)'
4344
    url = 'http://www.gocomics.com/sheldon'
4345
4346
4347
class FowlLanguageGoComics(GenericGoComic):
4348
    """Class to retrieve Fowl Language comics."""
4349
    # Also on http://www.fowllanguagecomics.com
4350
    # Also on http://tapastic.com/series/Fowl-Language-Comics
4351
    # Also on http://fowllanguagecomics.tumblr.com
4352
    name = 'fowllanguage-goc'
4353
    long_name = 'Fowl Language Comics (from GoComics)'
4354
    url = 'http://www.gocomics.com/fowl-language'
4355
    _categories = ('FOWLLANGUAGE', )
4356
4357
4358
class NickAnderson(GenericGoComic):
4359
    """Class to retrieve Nick Anderson comics."""
4360
    name = 'nickanderson'
4361
    long_name = 'Nick Anderson'
4362
    url = 'http://www.gocomics.com/nickanderson'
4363
4364
4365
class GarfieldGoComics(GenericGoComic):
4366
    """Class to retrieve Garfield comics."""
4367
    # Also on http://garfield.com
4368
    name = 'garfield-goc'
4369
    long_name = 'Garfield (from GoComics)'
4370
    url = 'http://www.gocomics.com/garfield'
4371
    _categories = ('GARFIELD', )
4372
4373
4374
class DorrisMcGoComics(GenericGoComic):
4375
    """Class to retrieve Dorris Mc Comics"""
4376
    # Also on http://dorrismccomics.com
4377
    name = 'dorrismc-goc'
4378
    long_name = 'Dorris Mc (from GoComics)'
4379
    url = 'http://www.gocomics.com/dorris-mccomics'
4380
4381
4382
class FoxTrot(GenericGoComic):
4383
    """Class to retrieve FoxTrot comics."""
4384
    name = 'foxtrot'
4385
    long_name = 'FoxTrot'
4386
    url = 'http://www.gocomics.com/foxtrot'
4387
4388
4389
class FoxTrotClassics(GenericGoComic):
4390
    """Class to retrieve FoxTrot Classics comics."""
4391
    name = 'foxtrot-classics'
4392
    long_name = 'FoxTrot Classics'
4393
    url = 'http://www.gocomics.com/foxtrotclassics'
4394
4395
4396
class MisterAndMeGoComics(GenericGoComic):
4397
    """Class to retrieve Mister & Me Comics."""
4398
    # Also on http://www.mister-and-me.com
4399
    # Also on https://tapastic.com/series/Mister-and-Me
4400
    name = 'mister-goc'
4401
    long_name = 'Mister & Me (from GoComics)'
4402
    url = 'http://www.gocomics.com/mister-and-me'
4403
4404
4405
class NonSequitur(GenericGoComic):
4406
    """Class to retrieve Non Sequitur (Wiley Miller) comics."""
4407
    name = 'nonsequitur'
4408
    long_name = 'Non Sequitur'
4409
    url = 'http://www.gocomics.com/nonsequitur'
4410
4411
4412
class GenericTapasticComic(GenericListableComic):
4413
    """Generic class to handle the logic common to comics from tapastic.com."""
4414
    _categories = ('TAPASTIC', )
4415
4416
    @classmethod
4417
    def get_comic_info(cls, soup, archive_elt):
4418
        """Get information about a particular comics."""
4419
        timestamp = int(archive_elt['publishDate']) / 1000.0
4420
        day = datetime.datetime.fromtimestamp(timestamp).date()
4421
        imgs = soup.find_all('img', class_='art-image')
4422
        if not imgs:
4423
            print("Comic %s is being uploaded, retry later" % cls.get_url_from_archive_element(archive_elt))
4424
            return None
4425
        assert len(imgs) > 0
4426
        return {
4427
            'day': day.day,
4428
            'year': day.year,
4429
            'month': day.month,
4430
            'img': [i['src'] for i in imgs],
4431
            'title': archive_elt['title'],
4432
        }
4433
4434
    @classmethod
4435
    def get_url_from_archive_element(cls, archive_elt):
4436
        return 'http://tapastic.com/episode/' + str(archive_elt['id'])
4437
4438
    @classmethod
4439
    def get_archive_elements(cls):
4440
        pref, suff = 'episodeList : ', ','
4441
        # Information is stored in the javascript part
4442
        # I don't know the clean way to get it so this is the ugly way.
4443
        string = [s[len(pref):-len(suff)] for s in (s.decode('utf-8').strip() for s in urlopen_wrapper(cls.url).readlines()) if s.startswith(pref) and s.endswith(suff)][0]
4444
        return json.loads(string)
4445
4446
4447
class VegetablesForDessert(GenericTapasticComic):
4448
    """Class to retrieve Vegetables For Dessert comics."""
4449
    # Also on http://vegetablesfordessert.tumblr.com
4450
    name = 'vegetables'
4451
    long_name = 'Vegetables For Dessert'
4452
    url = 'http://tapastic.com/series/vegetablesfordessert'
4453
4454
4455
class FowlLanguageTapa(GenericTapasticComic):
4456
    """Class to retrieve Fowl Language comics."""
4457
    # Also on http://www.fowllanguagecomics.com
4458
    # Also on http://fowllanguagecomics.tumblr.com
4459
    # Also on http://www.gocomics.com/fowl-language
4460
    name = 'fowllanguage-tapa'
4461
    long_name = 'Fowl Language Comics (from Tapastic)'
4462
    url = 'http://tapastic.com/series/Fowl-Language-Comics'
4463
    _categories = ('FOWLLANGUAGE', )
4464
4465
4466
class OscillatingProfundities(GenericTapasticComic):
4467
    """Class to retrieve Oscillating Profundities comics."""
4468
    name = 'oscillating'
4469
    long_name = 'Oscillating Profundities'
4470
    url = 'http://tapastic.com/series/oscillatingprofundities'
4471
4472
4473
class ZnoflatsComics(GenericTapasticComic):
4474
    """Class to retrieve Znoflats comics."""
4475
    name = 'znoflats'
4476
    long_name = 'Znoflats Comics'
4477
    url = 'http://tapastic.com/series/Znoflats-Comics'
4478
4479
4480
class SandersenTapastic(GenericTapasticComic):
4481
    """Class to retrieve Sarah Andersen comics."""
4482
    # Also on http://sarahcandersen.com
4483
    # Also on http://www.gocomics.com/sarahs-scribbles
4484
    name = 'sandersen-tapa'
4485
    long_name = 'Sarah Andersen (from Tapastic)'
4486
    url = 'http://tapastic.com/series/Doodle-Time'
4487
4488
4489
class TubeyToonsTapastic(GenericTapasticComic):
4490
    """Class to retrieve TubeyToons comics."""
4491
    # Also on http://tubeytoons.com
4492
    # Also on http://tubeytoons.tumblr.com
4493
    name = 'tubeytoons-tapa'
4494
    long_name = 'Tubey Toons (from Tapastic)'
4495
    url = 'http://tapastic.com/series/Tubey-Toons'
4496
    _categories = ('TUNEYTOONS', )
4497
4498
4499
class AnythingComicTapastic(GenericTapasticComic):
4500
    """Class to retrieve Anything Comics."""
4501
    # Also on http://www.anythingcomic.com
4502
    name = 'anythingcomic-tapa'
4503
    long_name = 'Anything Comic (from Tapastic)'
4504
    url = 'http://tapastic.com/series/anything'
4505
4506
4507
class UnearthedComicsTapastic(GenericTapasticComic):
4508
    """Class to retrieve Unearthed comics."""
4509
    # Also on http://unearthedcomics.com
4510
    # Also on http://unearthedcomics.tumblr.com
4511
    name = 'unearthed-tapa'
4512
    long_name = 'Unearthed Comics (from Tapastic)'
4513
    url = 'http://tapastic.com/series/UnearthedComics'
4514
    _categories = ('UNEARTHED', )
4515
4516
4517
class EverythingsStupidTapastic(GenericTapasticComic):
4518
    """Class to retrieve Everything's stupid Comics."""
4519
    # Also on http://www.webtoons.com/en/challenge/everythings-stupid/list?title_no=14591
4520
    # Also on http://everythingsstupid.net
4521
    name = 'stupid-tapa'
4522
    long_name = "Everything's Stupid (from Tapastic)"
4523
    url = 'http://tapastic.com/series/EverythingsStupid'
4524
4525
4526
class JustSayEhTapastic(GenericTapasticComic):
4527
    """Class to retrieve Just Say Eh comics."""
4528
    # Also on http://www.justsayeh.com
4529
    name = 'justsayeh-tapa'
4530
    long_name = 'Just Say Eh (from Tapastic)'
4531
    url = 'http://tapastic.com/series/Just-Say-Eh'
4532
4533
4534
class ThorsThundershackTapastic(GenericTapasticComic):
4535
    """Class to retrieve Thor's Thundershack comics."""
4536
    # Also on http://www.thorsthundershack.com
4537
    name = 'thor-tapa'
4538
    long_name = 'Thor\'s Thundershack (from Tapastic)'
4539
    url = 'http://tapastic.com/series/Thors-Thundershac'
4540
    _categories = ('THOR', )
4541
4542
4543
class OwlTurdTapastic(GenericTapasticComic):
4544
    """Class to retrieve Owl Turd comics."""
4545
    # Also on http://owlturd.com
4546
    name = 'owlturd-tapa'
4547
    long_name = 'Owl Turd (from Tapastic)'
4548
    url = 'http://tapastic.com/series/Owl-Turd-Comix'
4549
    _categories = ('OWLTURD', )
4550
4551
4552
class GoneIntoRaptureTapastic(GenericTapasticComic):
4553
    """Class to retrieve Gone Into Rapture comics."""
4554
    # Also on http://goneintorapture.tumblr.com
4555
    # Also on http://www.goneintorapture.com
4556
    name = 'rapture-tapa'
4557
    long_name = 'Gone Into Rapture (from Tapastic)'
4558
    url = 'http://tapastic.com/series/Goneintorapture'
4559
4560
4561
class HeckIfIKnowComicsTapa(GenericTapasticComic):
4562
    """Class to retrieve Heck If I Know Comics."""
4563
    # Also on http://heckifiknowcomics.com
4564
    name = 'heck-tapa'
4565
    long_name = 'Heck if I Know comics (from Tapastic)'
4566
    url = 'http://tapastic.com/series/Regular'
4567
4568
4569
class CheerUpEmoKidTapa(GenericTapasticComic):
4570
    """Class to retrieve CheerUpEmoKid comics."""
4571
    # Also on http://www.cheerupemokid.com
4572
    # Also on http://enzocomics.tumblr.com
4573
    name = 'cuek-tapa'
4574
    long_name = 'Cheer Up Emo Kid (from Tapastic)'
4575
    url = 'http://tapastic.com/series/CUEK'
4576
4577
4578
class BigFootJusticeTapa(GenericTapasticComic):
4579
    """Class to retrieve Big Foot Justice comics."""
4580
    # Also on http://bigfootjustice.com
4581
    name = 'bigfoot-tapa'
4582
    long_name = 'Big Foot Justice (from Tapastic)'
4583
    url = 'http://tapastic.com/series/bigfoot-justice'
4584
4585
4586
class UpAndOutTapa(GenericTapasticComic):
4587
    """Class to retrieve Up & Out comics."""
4588
    # Also on http://upandoutcomic.tumblr.com
4589
    name = 'upandout-tapa'
4590
    long_name = 'Up And Out (from Tapastic)'
4591
    url = 'http://tapastic.com/series/UP-and-OUT'
4592
4593
4594
class ToonHoleTapa(GenericTapasticComic):
4595
    """Class to retrieve Toon Holes comics."""
4596
    # Also on http://www.toonhole.com
4597
    name = 'toonhole-tapa'
4598
    long_name = 'Toon Hole (from Tapastic)'
4599
    url = 'http://tapastic.com/series/TOONHOLE'
4600
4601
4602
class AngryAtNothingTapa(GenericTapasticComic):
4603
    """Class to retrieve Angry at Nothing comics."""
4604
    # Also on http://www.angryatnothing.net
4605
    name = 'angry-tapa'
4606
    long_name = 'Angry At Nothing (from Tapastic)'
4607
    url = 'http://tapastic.com/series/Comics-yeah-definitely-comics-'
4608
4609
4610
class LeleozTapa(GenericTapasticComic):
4611
    """Class to retrieve Leleoz comics."""
4612
    # Also on http://leleozcomics.tumblr.com
4613
    name = 'leleoz-tapa'
4614
    long_name = 'Leleoz (from Tapastic)'
4615
    url = 'https://tapastic.com/series/Leleoz'
4616
4617
4618
class TheAwkwardYetiTapa(GenericTapasticComic):
4619
    """Class to retrieve The Awkward Yeti comics."""
4620
    # Also on http://www.gocomics.com/the-awkward-yeti
4621
    # Also on http://theawkwardyeti.com
4622
    # Also on http://larstheyeti.tumblr.com
4623
    name = 'yeti-tapa'
4624
    long_name = 'The Awkward Yeti (from Tapastic)'
4625
    url = 'https://tapastic.com/series/TheAwkwardYeti'
4626
    _categories = ('YETI', )
4627
4628
4629
class AsPerUsualTapa(GenericTapasticComic):
4630
    """Class to retrieve As Per Usual comics."""
4631
    # Also on http://as-per-usual.tumblr.com
4632
    name = 'usual-tapa'
4633
    long_name = 'As Per Usual (from Tapastic)'
4634
    url = 'https://tapastic.com/series/AsPerUsual'
4635
    categories = ('DAMILEE', )
4636
4637
4638
class HotComicsForCoolPeopleTapa(GenericTapasticComic):
4639
    """Class to retrieve Hot Comics For Cool People."""
4640
    # Also on http://hotcomicsforcoolpeople.tumblr.com
4641
    # Also on http://hotcomics.biz (links to tumblr)
4642
    # Also on http://hcfcp.com (links to tumblr)
4643
    name = 'hotcomics-tapa'
4644
    long_name = 'Hot Comics For Cool People (from Tapastic)'
4645
    url = 'https://tapastic.com/series/Hot-Comics-For-Cool-People'
4646
    categories = ('DAMILEE', )
4647
4648
4649
class OneOneOneOneComicTapa(GenericTapasticComic):
4650
    """Class to retrieve 1111 Comics."""
4651
    # Also on http://www.1111comics.me
4652
    # Also on http://comics1111.tumblr.com
4653
    name = '1111-tapa'
4654
    long_name = '1111 Comics (from Tapastic)'
4655
    url = 'https://tapastic.com/series/1111-Comics'
4656
    _categories = ('ONEONEONEONE', )
4657
4658
4659
class TumbleDryTapa(GenericTapasticComic):
4660
    """Class to retrieve Tumble Dry comics."""
4661
    # Also on http://tumbledrycomics.com
4662
    name = 'tumbledry-tapa'
4663
    long_name = 'Tumblr Dry (from Tapastic)'
4664
    url = 'https://tapastic.com/series/TumbleDryComics'
4665
4666
4667
class DeadlyPanelTapa(GenericTapasticComic):
4668
    """Class to retrieve Deadly Panel comics."""
4669
    # Also on http://www.deadlypanel.com
4670
    name = 'deadly-tapa'
4671
    long_name = 'Deadly Panel (from Tapastic)'
4672
    url = 'https://tapastic.com/series/deadlypanel'
4673
4674
4675
class ChrisHallbeckMaxiTapa(GenericTapasticComic):
4676
    """Class to retrieve Chris Hallbeck comics."""
4677
    # Also on http://chrishallbeck.tumblr.com
4678
    # Also on http://maximumble.com
4679
    name = 'hallbeckmaxi-tapa'
4680
    long_name = 'Chris Hallback - Maximumble (from Tapastic)'
4681
    url = 'https://tapastic.com/series/Maximumble'
4682
    _categories = ('HALLBACK', )
4683
4684
4685
class ChrisHallbeckMiniTapa(GenericTapasticComic):
4686
    """Class to retrieve Chris Hallbeck comics."""
4687
    # Also on http://chrishallbeck.tumblr.com
4688
    # Also on http://minimumble.com
4689
    name = 'hallbeckmini-tapa'
4690
    long_name = 'Chris Hallback - Minimumble (from Tapastic)'
4691
    url = 'https://tapastic.com/series/Minimumble'
4692
    _categories = ('HALLBACK', )
4693
4694
4695
class ChrisHallbeckBiffTapa(GenericTapasticComic):
4696
    """Class to retrieve Chris Hallbeck comics."""
4697
    # Also on http://chrishallbeck.tumblr.com
4698
    # Also on http://thebookofbiff.com
4699
    name = 'hallbeckbiff-tapa'
4700
    long_name = 'Chris Hallback - The Book of Biff (from Tapastic)'
4701
    url = 'https://tapastic.com/series/Biff'
4702
    _categories = ('HALLBACK', )
4703
4704
4705
class RandoWisTapa(GenericTapasticComic):
4706
    """Class to retrieve RandoWis comics."""
4707
    # Also on https://randowis.com
4708
    name = 'randowis-tapa'
4709
    long_name = 'RandoWis (from Tapastic)'
4710
    url = 'https://tapastic.com/series/RandoWis'
4711
4712
4713
class PigeonGazetteTapa(GenericTapasticComic):
4714
    """Class to retrieve The Pigeon Gazette comics."""
4715
    # Also on http://thepigeongazette.tumblr.com
4716
    name = 'pigeon-tapa'
4717
    long_name = 'The Pigeon Gazette (from Tapastic)'
4718
    url = 'https://tapastic.com/series/The-Pigeon-Gazette'
4719
4720
4721
class TheOdd1sOutTapa(GenericTapasticComic):
4722
    """Class to retrieve The Odd 1s Out comics."""
4723
    # Also on http://theodd1sout.com
4724
    # Also on http://theodd1sout.tumblr.com
4725
    name = 'theodd-tapa'
4726
    long_name = 'The Odd 1s Out (from Tapastic)'
4727
    url = 'https://tapastic.com/series/Theodd1sout'
4728
4729
4730
class TheWorldIsFlatTapa(GenericTapasticComic):
4731
    """Class to retrieve The World Is Flat Comics."""
4732
    # Also on http://theworldisflatcomics.tumblr.com
4733
    name = 'flatworld-tapa'
4734
    long_name = 'The World Is Flat (from Tapastic)'
4735
    url = 'https://tapastic.com/series/The-World-is-Flat'
4736
4737
4738
class MisterAndMeTapa(GenericTapasticComic):
4739
    """Class to retrieve Mister & Me Comics."""
4740
    # Also on http://www.mister-and-me.com
4741
    # Also on http://www.gocomics.com/mister-and-me
4742
    name = 'mister-tapa'
4743
    long_name = 'Mister & Me (from Tapastic)'
4744
    url = 'https://tapastic.com/series/Mister-and-Me'
4745
4746
4747
class TalesOfAbsurdityTapa(GenericTapasticComic):
4748
    """Class to retrieve Tales Of Absurdity comics."""
4749
    # Also on http://talesofabsurdity.com
4750
    # Also on http://talesofabsurdity.tumblr.com
4751
    name = 'absurdity-tapa'
4752
    long_name = 'Tales of Absurdity (from Tapastic)'
4753
    url = 'http://tapastic.com/series/Tales-Of-Absurdity'
4754
    _categories = ('ABSURDITY', )
4755
4756
4757
class BFGFSTapa(GenericTapasticComic):
4758
    """Class to retrieve BFGFS comics."""
4759
    # Also on http://bfgfs.com
4760
    # Also on http://bfgfs.tumblr.com
4761
    name = 'bfgfs-tapa'
4762
    long_name = 'BFGFS (from Tapastic)'
4763
    url = 'https://tapastic.com/series/BFGFS'
4764
4765
4766
class DoodleForFoodTapa(GenericTapasticComic):
4767
    """Class to retrieve Doodle For Food comics."""
4768
    # Also on http://doodleforfood.com
4769
    name = 'doodle-tapa'
4770
    long_name = 'Doodle For Food (from Tapastic)'
4771
    url = 'https://tapastic.com/series/Doodle-for-Food'
4772
4773
4774
class MrLovensteinTapa(GenericTapasticComic):
4775
    """Class to retrieve Mr Lovenstein comics."""
4776
    # Also on  https://tapastic.com/series/MrLovenstein
4777
    name = 'mrlovenstein-tapa'
4778
    long_name = 'Mr. Lovenstein (from Tapastic)'
4779
    url = 'https://tapastic.com/series/MrLovenstein'
4780
4781
4782
class CassandraCalinTapa(GenericTapasticComic):
4783
    """Class to retrieve C. Cassandra comics."""
4784
    # Also on http://cassandracalin.com
4785
    # Also on http://c-cassandra.tumblr.com
4786
    name = 'cassandra-tapa'
4787
    long_name = 'Cassandra Calin (from Tapastic)'
4788
    url = 'https://tapastic.com/series/C-Cassandra-comics'
4789
4790
4791
class WafflesAndPancakes(GenericTapasticComic):
4792
    """Class to retrieve Waffles And Pancakes comics."""
4793
    # Also on http://wandpcomic.com
4794
    name = 'waffles'
4795
    long_name = 'Waffles And Pancakes'
4796
    url = 'https://tapastic.com/series/Waffles-and-Pancakes'
4797
4798
4799
class YesterdaysPopcornTapastic(GenericTapasticComic):
4800
    """Class to retrieve Yesterday's Popcorn comics."""
4801
    # Also on http://www.yesterdayspopcorn.com
4802
    # Also on http://yesterdayspopcorn.tumblr.com
4803
    name = 'popcorn-tapa'
4804
    long_name = 'Yesterday\'s Popcorn (from Tapastic)'
4805
    url = 'https://tapastic.com/series/Yesterdays-Popcorn'
4806
4807
4808
class OurSuperAdventureTapastic(GenericTapasticComic):
4809
    """Class to retrieve Our Super Adventure comics."""
4810
    # Also on http://www.oursuperadventure.com
4811
    # http://sarahssketchbook.tumblr.com
4812
    # http://sarahgraley.com
4813
    name = 'superadventure-tapastic'
4814
    long_name = 'Our Super Adventure (from Tapastic)'
4815
    url = 'https://tapastic.com/series/Our-Super-Adventure'
4816
4817
4818
class NamelessPCs(GenericTapasticComic):
4819
    """Class to retrieve Nameless PCs comics."""
4820
    # Also on http://namelesspcs.com
4821
    name = 'namelesspcs-tapa'
4822
    long_name = 'NamelessPCs (from Tapastic)'
4823
    url = 'https://tapastic.com/series/NamelessPC'
4824
4825
4826
class UbertoolTapa(GenericTapasticComic):
4827
    """Class to retrieve Ubertool comics."""
4828
    # Also on http://ubertoolcomic.com
4829
    # Also on http://ubertool.tumblr.com
4830
    name = 'ubertool-tapa'
4831
    long_name = 'Ubertool (from Tapastic)'
4832
    url = 'https://tapastic.com/series/ubertool'
4833
    _categories = ('UBERTOOL', )
4834
4835
4836
class SmallBlueYonderTapa(GenericTapasticComic):
4837
    """Class to retrieve Small Blue Yonder comics."""
4838
    # Also on http://www.smallblueyonder.com
4839
    name = 'smallblue-tapa'
4840
    long_name = 'Small Blue Yonder (from Tapastic)'
4841
    url = 'https://tapastic.com/series/Small-Blue-Yonder'
4842
4843
4844
def get_subclasses(klass):
4845
    """Gets the list of direct/indirect subclasses of a class"""
4846
    subclasses = klass.__subclasses__()
4847
    for derived in list(subclasses):
4848
        subclasses.extend(get_subclasses(derived))
4849
    return subclasses
4850
4851
4852
def remove_st_nd_rd_th_from_date(string):
4853
    """Function to transform 1st/2nd/3rd/4th in a parsable date format."""
4854
    # Hackish way to convert string with numeral "1st"/"2nd"/etc to date
4855
    return (string.replace('st', '')
4856
            .replace('nd', '')
4857
            .replace('rd', '')
4858
            .replace('th', '')
4859
            .replace('Augu', 'August'))
4860
4861
4862
def string_to_date(string, date_format, local=DEFAULT_LOCAL):
4863
    """Function to convert string to date object.
4864
    Wrapper around datetime.datetime.strptime."""
4865
    # format described in https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior
4866
    prev_locale = locale.setlocale(locale.LC_ALL)
4867
    if local != prev_locale:
4868
        locale.setlocale(locale.LC_ALL, local)
4869
    ret = datetime.datetime.strptime(string, date_format).date()
4870
    if local != prev_locale:
4871
        locale.setlocale(locale.LC_ALL, prev_locale)
4872
    return ret
4873
4874
4875
COMICS = set(get_subclasses(GenericComic))
4876
VALID_COMICS = [c for c in COMICS if c.name is not None]
4877
COMIC_NAMES = {c.name: c for c in VALID_COMICS}
4878
assert len(VALID_COMICS) == len(COMIC_NAMES)
4879
CLASS_NAMES = {c.__name__ for c in VALID_COMICS}
4880
assert len(VALID_COMICS) == len(CLASS_NAMES)
4881