| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
__license__ = 'GPL v3' |
| 4 |
__copyright__ = 'Copyright 2010 Starson17' |
| 5 |
''' |
| 6 |
www.arcamax.com |
| 7 |
''' |
| 8 |
|
| 9 |
import os |
| 10 |
|
| 11 |
from calibre.ptempfile import PersistentTemporaryDirectory |
| 12 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 13 |
|
| 14 |
|
| 15 |
class Arcamax(BasicNewsRecipe): |
| 16 |
title = 'Arcamax' |
| 17 |
__author__ = 'Kovid Goyal' |
| 18 |
description = 'Family Friendly Comics - Customize for more days/comics: Defaults to 7 days, 25 comics - 20 general, 5 editorial.' |
| 19 |
category = 'news, comics' |
| 20 |
language = 'en' |
| 21 |
use_embedded_content = False |
| 22 |
no_stylesheets = True |
| 23 |
remove_javascript = True |
| 24 |
simultaneous_downloads = 1 |
| 25 |
cover_url = 'https://www.arcamax.com/images/pub/amuse/leftcol/zits.jpg' |
| 26 |
|
| 27 |
# ###### USER PREFERENCES - SET COMICS AND NUMBER OF COMICS TO RETRIEVE ## |
| 28 |
num_comics_to_get = 7 |
| 29 |
# CHOOSE COMIC STRIPS BELOW - REMOVE COMMENT '# ' FROM IN FRONT OF DESIRED |
| 30 |
# STRIPS |
| 31 |
|
| 32 |
recipe_specific_options = {'days': {'short': 'NUMBER OF COMICS TO RETRIEVE', 'default': str(num_comics_to_get)}} |
| 33 |
|
| 34 |
def __init__(self, *args, **kwargs): |
| 35 |
BasicNewsRecipe.__init__(self, *args, **kwargs) |
| 36 |
d = self.recipe_specific_options.get('days') |
| 37 |
if d and isinstance(d, str): |
| 38 |
self.num_comics_to_get = float(d) |
| 39 |
|
| 40 |
conversion_options = {'linearize_tables': True, 'comment': description, 'tags': category, 'language': language} |
| 41 |
|
| 42 |
keep_only_tags = [ |
| 43 |
dict(name='header', attrs={'class': 'fn-content-header bluelabel', 'style': False}), |
| 44 |
dict(name='figure', attrs={'class': ['comic']}), |
| 45 |
] |
| 46 |
|
| 47 |
remove_tags_after = [ |
| 48 |
dict(name='figure', attrs={'class': ['comic']}), |
| 49 |
] |
| 50 |
|
| 51 |
def parse_index(self): |
| 52 |
feeds = [] |
| 53 |
self.panel_tdir = PersistentTemporaryDirectory('arcamax') |
| 54 |
self.panel_counter = 0 |
| 55 |
|
| 56 |
# https://www.arcamax.com/comics |
| 57 |
|
| 58 |
for title, url in [ |
| 59 |
# ####### COMICS - GENERAL ######## |
| 60 |
# (u"9 Chickweed Lane", u"https://www.arcamax.com/thefunnies/ninechickweedlane"), |
| 61 |
# (u"Agnes", u"https://www.arcamax.com/thefunnies/agnes"), |
| 62 |
# (u"Andy Capp", u"https://www.arcamax.com/thefunnies/andycapp"), |
| 63 |
('BC', 'https://www.arcamax.com/thefunnies/bc'), |
| 64 |
# (u"Baby Blues", u"https://www.arcamax.com/thefunnies/babyblues"), |
| 65 |
# (u"Beetle Bailey", u"https://www.arcamax.com/thefunnies/beetlebailey"), |
| 66 |
('Blondie', 'https://www.arcamax.com/thefunnies/blondie'), |
| 67 |
# u"Boondocks", u"https://www.arcamax.com/thefunnies/boondocks"), |
| 68 |
# (u"Cathy", u"https://www.arcamax.com/thefunnies/cathy"), |
| 69 |
# (u"Daddys Home", u"https://www.arcamax.com/thefunnies/daddyshome"), |
| 70 |
# (u"Dinette Set", u"https://www.arcamax.com/thefunnies/thedinetteset"), |
| 71 |
('Dog Eat Doug', 'https://www.arcamax.com/thefunnies/dogeatdoug'), |
| 72 |
# (u"Doonesbury", u"https://www.arcamax.com/thefunnies/doonesbury"), |
| 73 |
# (u"Dustin", u"https://www.arcamax.com/thefunnies/dustin"), |
| 74 |
('Family Circus', 'https://www.arcamax.com/thefunnies/familycircus'), |
| 75 |
('Garfield', 'https://www.arcamax.com/thefunnies/garfield'), |
| 76 |
# (u"Get Fuzzy", u"https://www.arcamax.com/thefunnies/getfuzzy"), |
| 77 |
# (u"Girls and Sports", u"https://www.arcamax.com/thefunnies/girlsandsports"), |
| 78 |
# (u"Hagar the Horrible", u"https://www.arcamax.com/thefunnies/hagarthehorrible"), |
| 79 |
# (u"Heathcliff", u"https://www.arcamax.com/thefunnies/heathcliff"), |
| 80 |
# (u"Jerry King Cartoons", u"https://www.arcamax.com/thefunnies/humorcartoon"), |
| 81 |
# (u"Luann", u"https://www.arcamax.com/thefunnies/luann"), |
| 82 |
# (u"Momma", u"https://www.arcamax.com/thefunnies/momma"), |
| 83 |
# (u"Mother Goose and Grimm", u"https://www.arcamax.com/thefunnies/mothergooseandgrimm"), |
| 84 |
('Mutts', 'https://www.arcamax.com/thefunnies/mutts'), |
| 85 |
# (u"Non Sequitur", u"https://www.arcamax.com/thefunnies/nonsequitur"), |
| 86 |
# (u"Pearls Before Swine", u"https://www.arcamax.com/thefunnies/pearlsbeforeswine"), |
| 87 |
# (u"Pickles", u"https://www.arcamax.com/thefunnies/pickles"), |
| 88 |
# (u"Red and Rover", u"https://www.arcamax.com/thefunnies/redandrover"), |
| 89 |
# (u"Rubes", u"https://www.arcamax.com/thefunnies/rubes"), |
| 90 |
# (u"Rugrats", u"https://www.arcamax.com/thefunnies/rugrats"), |
| 91 |
('Speed Bump', 'https://www.arcamax.com/thefunnies/speedbump'), |
| 92 |
('Wizard of Id', 'https://www.arcamax.com/thefunnies/wizardofid'), |
| 93 |
('Zits', 'https://www.arcamax.com/thefunnies/zits'), |
| 94 |
]: |
| 95 |
self.log('Finding strips for:', title) |
| 96 |
articles = self.make_links(url, title) |
| 97 |
if articles: |
| 98 |
feeds.append((title, articles)) |
| 99 |
if self.test and len(feeds) >= self.test[0]: |
| 100 |
break |
| 101 |
return feeds |
| 102 |
|
| 103 |
def make_links(self, url, title): |
| 104 |
current_articles = [] |
| 105 |
num = self.num_comics_to_get |
| 106 |
while num > 0: |
| 107 |
num -= 1 |
| 108 |
raw = self.index_to_soup(url, raw=True) |
| 109 |
self.panel_counter += 1 |
| 110 |
path = os.path.join(self.panel_tdir, '%d.html' % self.panel_counter) |
| 111 |
with open(path, 'wb') as f: |
| 112 |
f.write(raw) |
| 113 |
soup = self.index_to_soup(raw) |
| 114 |
a = soup.find(name='a', attrs={'class': ['prev']}) |
| 115 |
prev_page_url = 'https://www.arcamax.com' + a['href'] |
| 116 |
title = self.tag_to_string(soup.find('title')).partition('|')[0].strip() |
| 117 |
if 'for' not in title.split(): |
| 118 |
title = title + ' for today' |
| 119 |
date = self.tag_to_string(soup.find(name='span', attrs={'class': ['cur']})) |
| 120 |
self.log('\tFound:', title, 'at:', url) |
| 121 |
current_articles.append({'title': title, 'url': 'file://' + path, 'description': '', 'date': date}) |
| 122 |
if self.test and len(current_articles) >= self.test[1]: |
| 123 |
break |
| 124 |
url = prev_page_url |
| 125 |
current_articles.reverse() |
| 126 |
return current_articles |
| 127 |
|
| 128 |
def preprocess_html(self, soup): |
| 129 |
for img in soup.findAll('img', src=True): |
| 130 |
if img['src'].startswith('/'): |
| 131 |
img['src'] = 'https://arcamax.com' + img['src'] |
| 132 |
return soup |
| 133 |
|
| 134 |
extra_css = ''' |
| 135 |
img { display:block; margin:0 auto; } |
| 136 |
''' |