Code Duplication    Length = 22-29 lines in 12 locations

comics.py 12 locations

@@ 911-936 (lines=26) @@
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
@@ 2274-2298 (lines=25) @@
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
    # Now on https://warandpeas.com
2278
    name = 'lins'
2279
    long_name = 'L.I.N.S. Editions'
2280
    url = 'https://linsedition.com'
2281
    _categories = ('LINS', )
2282
    get_navi_link = get_link_rel_next
2283
    get_first_comic_link = simulate_first_link
2284
    first_url = 'https://linsedition.com/2011/09/07/l-i-n-s/'
2285
2286
    @classmethod
2287
    def get_comic_info(cls, soup, link):
2288
        """Get information about a particular comics."""
2289
        title = soup.find('meta', property='og:title')['content']
2290
        imgs = soup.find_all('meta', property='og:image')
2291
        date_str = soup.find('meta', property='article:published_time')['content'][:10]
2292
        day = string_to_date(date_str, "%Y-%m-%d")
2293
        return {
2294
            'title': title,
2295
            'img': [i['content'] for i in imgs],
2296
            'month': day.month,
2297
            'year': day.year,
2298
            'day': day.day,
2299
        }
2300
2301
@@ 341-363 (lines=23) @@
338
        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-388 (lines=22) @@
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
@@ 1801-1826 (lines=26) @@
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
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
@@ 2545-2573 (lines=29) @@
2542
        }
2543
2544
2545
class TalesOfAbsurdity(GenericNavigableComic):
2546
    """Class to retrieve Tales Of Absurdity comics."""
2547
    # Also on http://tapastic.com/series/Tales-Of-Absurdity
2548
    # Also on http://talesofabsurdity.tumblr.com
2549
    name = 'absurdity'
2550
    long_name = 'Tales of Absurdity'
2551
    url = 'http://talesofabsurdity.com'
2552
    _categories = ('ABSURDITY', )
2553
    get_first_comic_link = get_a_navi_navifirst
2554
    get_navi_link = get_a_navi_comicnavnext_navinext
2555
2556
    @classmethod
2557
    def get_comic_info(cls, soup, link):
2558
        """Get information about a particular comics."""
2559
        title = soup.find('h2', class_='post-title').string
2560
        author = soup.find("span", class_="post-author").find("a").string
2561
        date_str = soup.find("span", class_="post-date").string
2562
        day = string_to_date(date_str, "%B %d, %Y")
2563
        imgs = soup.find("div", id="comic").find_all("img")
2564
        assert all(i['alt'] == i['title'] for i in imgs)
2565
        alt = imgs[0]['alt'] if imgs else ""
2566
        return {
2567
            'img': [i['src'] for i in imgs],
2568
            'title': title,
2569
            'alt': alt,
2570
            'author': author,
2571
            'day': day.day,
2572
            'month': day.month,
2573
            'year': day.year
2574
        }
2575
2576
@@ 2769-2795 (lines=27) @@
2766
        }
2767
2768
2769
class Optipess(GenericNavigableComic):
2770
    """Class to retrieve Optipess comics."""
2771
    name = 'optipess'
2772
    long_name = 'Optipess'
2773
    url = 'http://www.optipess.com'
2774
    get_first_comic_link = get_a_navi_navifirst
2775
    get_navi_link = get_link_rel_next
2776
2777
    @classmethod
2778
    def get_comic_info(cls, soup, link):
2779
        """Get information about a particular comics."""
2780
        title = soup.find('h2', class_='post-title').string
2781
        author = soup.find("span", class_="post-author").find("a").string
2782
        comic = soup.find('div', id='comic')
2783
        imgs = comic.find_all('img') if comic else []
2784
        alt = imgs[0]['title'] if imgs else ""
2785
        assert all(i['alt'] == i['title'] == alt for i in imgs)
2786
        date_str = soup.find('span', class_='post-date').string
2787
        day = string_to_date(date_str, "%B %d, %Y")
2788
        return {
2789
            'title': title,
2790
            'alt': alt,
2791
            'author': author,
2792
            'img': [i['src'] for i in imgs],
2793
            'month': day.month,
2794
            'year': day.year,
2795
            'day': day.day,
2796
        }
2797
2798
@@ 2515-2541 (lines=27) @@
2512
        }
2513
2514
2515
class LastPlaceComics(GenericNavigableComic):
2516
    """Class to retrieve Last Place Comics."""
2517
    name = 'lastplace'
2518
    long_name = 'Last Place Comics'
2519
    url = "http://lastplacecomics.com"
2520
    get_first_comic_link = get_a_comicnavbase_comicnavfirst
2521
    get_navi_link = get_link_rel_next
2522
2523
    @classmethod
2524
    def get_comic_info(cls, soup, link):
2525
        """Get information about a particular comics."""
2526
        title = soup.find('h2', class_='post-title').string
2527
        author = soup.find("span", class_="post-author").find("a").string
2528
        date_str = soup.find("span", class_="post-date").string
2529
        day = string_to_date(date_str, "%B %d, %Y")
2530
        imgs = soup.find("div", id="comic").find_all("img")
2531
        assert all(i['alt'] == i['title'] for i in imgs)
2532
        assert len(imgs) <= 1
2533
        alt = imgs[0]['alt'] if imgs else ""
2534
        return {
2535
            'img': [i['src'] for i in imgs],
2536
            'title': title,
2537
            'alt': alt,
2538
            'author': author,
2539
            'day': day.day,
2540
            'month': day.month,
2541
            'year': day.year
2542
        }
2543
2544
@@ 2404-2430 (lines=27) @@
2401
        }
2402
2403
2404
class BiterComics(GenericNavigableComic):
2405
    """Class to retrieve Biter Comics."""
2406
    name = "biter"
2407
    long_name = "Biter Comics"
2408
    url = "http://www.bitercomics.com"
2409
    get_first_comic_link = get_a_navi_navifirst
2410
    get_navi_link = get_link_rel_next
2411
2412
    @classmethod
2413
    def get_comic_info(cls, soup, link):
2414
        """Get information about a particular comics."""
2415
        title = soup.find("h1", class_="entry-title").string
2416
        author = soup.find("span", class_="author vcard").find("a").string
2417
        date_str = soup.find("span", class_="entry-date").string
2418
        day = string_to_date(date_str, "%B %d, %Y")
2419
        imgs = soup.find("div", id="comic").find_all("img")
2420
        assert all(i['alt'] == i['title'] for i in imgs)
2421
        assert len(imgs) == 1
2422
        alt = imgs[0]['alt']
2423
        return {
2424
            'img': [i['src'] for i in imgs],
2425
            'title': title,
2426
            'alt': alt,
2427
            'author': author,
2428
            'day': day.day,
2429
            'month': day.month,
2430
            'year': day.year
2431
        }
2432
2433
@@ 1953-1979 (lines=27) @@
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
@@ 2577-2602 (lines=26) @@
2574
        }
2575
2576
2577
class EndlessOrigami(GenericEmptyComic, GenericNavigableComic):
2578
    """Class to retrieve Endless Origami Comics."""
2579
    name = "origami"
2580
    long_name = "Endless Origami"
2581
    url = "http://endlessorigami.com"
2582
    get_first_comic_link = get_a_navi_navifirst
2583
    get_navi_link = get_link_rel_next
2584
2585
    @classmethod
2586
    def get_comic_info(cls, soup, link):
2587
        """Get information about a particular comics."""
2588
        title = soup.find('h2', class_='post-title').string
2589
        author = soup.find("span", class_="post-author").find("a").string
2590
        date_str = soup.find("span", class_="post-date").string
2591
        day = string_to_date(date_str, "%B %d, %Y")
2592
        imgs = soup.find("div", id="comic").find_all("img")
2593
        assert all(i['alt'] == i['title'] for i in imgs)
2594
        alt = imgs[0]['alt'] if imgs else ""
2595
        return {
2596
            'img': [i['src'] for i in imgs],
2597
            'title': title,
2598
            'alt': alt,
2599
            'author': author,
2600
            'day': day.day,
2601
            'month': day.month,
2602
            'year': day.year
2603
        }
2604
2605
@@ 2041-2065 (lines=25) @@
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