Code Duplication    Length = 22-26 lines in 5 locations

comics.py 5 locations

@@ 958-983 (lines=26) @@
955
        }
956
957
958
class MyExtraLife(GenericNavigableComic):
959
    """Class to retrieve My Extra Life comics."""
960
    name = 'extralife'
961
    long_name = 'My Extra Life'
962
    url = 'http://www.myextralife.com'
963
    get_navi_link = get_link_rel_next
964
965
    @classmethod
966
    def get_first_comic_link(cls):
967
        """Get link to first comics."""
968
        return get_soup_at_url(cls.url).find('a', class_='comic_nav_link first_comic_link')
969
970
    @classmethod
971
    def get_comic_info(cls, soup, link):
972
        """Get information about a particular comics."""
973
        title = soup.find("h1", class_="comic_title").string
974
        date_str = soup.find("span", class_="comic_date").string
975
        day = string_to_date(date_str, "%B %d, %Y")
976
        imgs = soup.find_all("img", class_="comic")
977
        assert all(i['alt'] == i['title'] == title for i in imgs)
978
        return {
979
            'title': title,
980
            'img': [i['src'] for i in imgs if i["src"]],
981
            'day': day.day,
982
            'month': day.month,
983
            'year': day.year
984
        }
985
986
@@ 386-407 (lines=22) @@
383
        }
384
385
386
class GenericLeMondeBlog(GenericNavigableComic):
387
    """Generic class to retrieve comics from Le Monde blogs."""
388
    _categories = ('LEMONDE', 'FRANCAIS')
389
    get_navi_link = get_link_rel_next
390
    get_first_comic_link = simulate_first_link
391
    first_url = NotImplemented
392
393
    @classmethod
394
    def get_comic_info(cls, soup, link):
395
        """Get information about a particular comics."""
396
        url2 = soup.find('link', rel='shortlink')['href']
397
        title = soup.find('meta', property='og:title')['content']
398
        date_str = soup.find("span", class_="entry-date").string
399
        day = string_to_date(date_str, "%d %B %Y", "fr_FR.utf8")
400
        imgs = soup.find_all('meta', property='og:image')
401
        return {
402
            'title': title,
403
            'url2': url2,
404
            'img': [convert_iri_to_plain_ascii_uri(i['content']) for i in imgs],
405
            'month': day.month,
406
            'year': day.year,
407
            'day': day.day,
408
        }
409
410
@@ 2374-2398 (lines=25) @@
2371
        }
2372
2373
2374
class LinsEditions(GenericNavigableComic):
2375
    """Class to retrieve L.I.N.S. Editions comics."""
2376
    # Also on https://linscomics.tumblr.com
2377
    # Now on https://warandpeas.com
2378
    name = 'lins'
2379
    long_name = 'L.I.N.S. Editions'
2380
    url = 'https://linsedition.com'
2381
    _categories = ('LINS', )
2382
    get_navi_link = get_link_rel_next
2383
    get_first_comic_link = simulate_first_link
2384
    first_url = 'https://linsedition.com/2011/09/07/l-i-n-s/'
2385
2386
    @classmethod
2387
    def get_comic_info(cls, soup, link):
2388
        """Get information about a particular comics."""
2389
        title = soup.find('meta', property='og:title')['content']
2390
        imgs = soup.find_all('meta', property='og:image')
2391
        date_str = soup.find('meta', property='article:published_time')['content'][:10]
2392
        day = string_to_date(date_str, "%Y-%m-%d")
2393
        return {
2394
            'title': title,
2395
            'img': [i['content'] for i in imgs],
2396
            'month': day.month,
2397
            'year': day.year,
2398
            'day': day.day,
2399
        }
2400
2401
@@ 3315-3336 (lines=22) @@
3312
        }
3313
3314
3315
class MarketoonistComics(GenericNavigableComic):
3316
    """Class to retrieve Marketoonist Comics."""
3317
    name = 'marketoonist'
3318
    long_name = 'Marketoonist'
3319
    url = 'https://marketoonist.com/cartoons'
3320
    get_first_comic_link = simulate_first_link
3321
    get_navi_link = get_link_rel_next
3322
    first_url = 'https://marketoonist.com/2002/10/the-8-types-of-brand-managers-2.html'
3323
3324
    @classmethod
3325
    def get_comic_info(cls, soup, link):
3326
        """Get information about a particular comics."""
3327
        imgs = soup.find_all('meta', property='og:image')
3328
        date_str = soup.find('meta', property='article:published_time')['content'][:10]
3329
        day = string_to_date(date_str, "%Y-%m-%d")
3330
        title = soup.find('meta', property='og:title')['content']
3331
        return {
3332
            'img': [i['content'] for i in imgs],
3333
            'day': day.day,
3334
            'month': day.month,
3335
            'year': day.year,
3336
            'title': title,
3337
        }
3338
3339
@@ 1046-1070 (lines=25) @@
1043
        }
1044
1045
1046
class Mercworks(GenericNavigableComic):
1047
    """Class to retrieve Mercworks comics."""
1048
    # Also on http://mercworks.tumblr.com
1049
    name = 'mercworks'
1050
    long_name = 'Mercworks'
1051
    url = 'http://mercworks.net'
1052
    get_first_comic_link = get_a_comicnavbase_comicnavfirst
1053
    get_navi_link = get_link_rel_next
1054
1055
    @classmethod
1056
    def get_comic_info(cls, soup, link):
1057
        """Get information about a particular comics."""
1058
        title = soup.find('meta', property='og:title')['content']
1059
        metadesc = soup.find('meta', property='og:description')
1060
        desc = metadesc['content'] if metadesc else ""
1061
        date_str = soup.find('meta', property='article:published_time')['content'][:10]
1062
        day = string_to_date(date_str, "%Y-%m-%d")
1063
        imgs = soup.find_all('meta', property='og:image')
1064
        return {
1065
            'img': [i['content'] for i in imgs],
1066
            'title': title,
1067
            'desc': desc,
1068
            'day': day.day,
1069
            'month': day.month,
1070
            'year': day.year
1071
        }
1072
1073