| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
# Calibre recipe for Instapaper.com (Stable version) |
| 4 |
# |
| 5 |
# Homepage: http://khromov.wordpress.com/projects/instapaper-calibre-recipe/ |
| 6 |
# Source: https://github.com/kovidgoyal/calibre/blob/master/recipes/instapaper.recipe |
| 7 |
# Last updated 10 July 2024 |
| 8 |
|
| 9 |
|
| 10 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 11 |
|
| 12 |
# The Gutenweb stylesheet from https://www.mobileread.com/forums/showpost.php?p=2809828&postcount=31 |
| 13 |
gutenweb = '''"html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:\'\';content:none}table{border-collapse:collapse;border-spacing:0}html,:root{font-size:16px}body{font-size:1em;line-height:1.5em;margin-top:1.5em;margin-bottom:1.5em;max-width:33em;margin-left:auto;margin-right:auto;font-family:Helvetica,Arial,sans-serif;text-align:left;word-spacing:normal;hyphens:auto;orphans:2;widows:2;font-variant-numeric:oldstyle-nums}body *{max-width:100%}address,article,aside,audio,canvas,footer,header,ol,ul,dl,pre,section,table,video,img,figure{margin-top:1.5em;margin-bottom:1.5em}p{margin-top:1.5em;margin-bottom:0em}p+p{margin-top:0em;margin-bottom:0em;text-indent:1.5em}h1{font-size:2.25em;line-height:1.33333em;margin-top:0.66667em;margin-bottom:0.66667em}h2{font-size:1.5em;line-height:1em;margin-top:1em;margin-bottom:1em}h3{font-size:1.3125em;line-height:1.14286em;margin-top:1.14286em;margin-bottom:1.14286em}h4{font-size:1.125em;line-height:1.33333em;margin-top:1.33333em;margin-bottom:1.33333em}h1,h2,h3,h4,h5,h6{font-family:Georgia,serif;font-weight:bold;page-break-after:avoid}ul li{list-style-type:disc}ol li{list-style-type:decimal}li{list-style-position:inside;text-indent:1.5em}dt{font-weight:bold;float:left;margin-right:1.5em}tr{page-break-before:avoid;page-break-after:avoid}td,th{outline:0.1em solid #000;padding:0 0.5em;text-align:left}tfoot td{font-style:italic}caption{font-style:italic;text-align:center;font-style:italic}blockquote{margin-top:2.25em;margin-bottom:2.25em;margin-left:2.25em;margin-right:2.25em}blockquote p{margin-top:0em;margin-bottom:0em;text-indent:0}figure{text-align:center}figure img,figure audio,figure canvas,figure video,figure table{margin-top:0;margin-bottom:0}figcaption{font-size:0.875em;line-height:1.71429em;margin-top:0em;margin-bottom:1.71429em;font-style:italic}img{vertical-align:bottom}code,samp,kbd,var{font-family:Consolas,"Liberation Mono",Courier,monospace;font-size:0.875em;font-weight:normal;font-style:normal;text-decoration:none;line-height:0.875em;padding:0 0.3em}mark{background:#ff0;color:#000}code,.code,samp,kbd,var{background-color:#f8f8f8;box-shadow:0 0 0.1em 0.1em #ddd}em{font-style:italic}strong{font-weight:bold}abbr{letter-spacing:0.1em}abbr[title]{border-bottom:1px dotted #000}cite,q{font-style:italic}q{font-style:italic;quotes:"\xe2\x80\x9c" "\xe2\x80\x9d" "\xe2\x80\x98" "\xe2\x80\x99"}q:before{content:open-quote}q:after{content:close-quote}dfn{font-style:italic}sup,sub{font-size:70%;line-height:70%;position:relative}sup{top:-0.5em}sub{top:0.5em}hr{border-bottom:0.0625em solid #000;border-top:0 none;border-left:0 none;border-right:0 none;margin-top:1.4375em;margin-bottom:1.5em}small{font-size:0.875em;line-height:1.71429em;margin-top:1.71429em;margin-bottom:1.71429em}i{font-style:italic}b{font-weight:bold}u{text-decoration:underline}s{text-decoration:line-through}ins{font-weight:bold;text-decoration:underline}del{text-decoration:line-through}.caps,.nums{letter-spacing:0.1em}.caps{font-variant-numeric:lining-nums}.code{overflow:auto;padding:0 1em;background-color:#f8f8f8;box-shadow:0 0 0.1em 0.1em #ddd}.code code,.code samp,.code kbd,.code var{box-shadow:none;padding:0}.chapter{page-break-after:auto;page-break-before:always}.note{text-indent:0;font-size:0.875em;line-height:1.71429em;margin-top:1.71429em;margin-bottom:1.71429em}.verse{font-family:inherit;display:table;width:auto;margin-left:auto;margin-right:auto}.toc{margin:0 auto}.toc td,.toc th{outline:0 none}.toc th{padding:0 0.5em 0 0;text-align:right;font-weight:normal}.toc td:before{content:"\\2022";padding-right:0.5em}.toc td{padding:0;text-align:left;font-style:italic}@page{margin-top:72pt;margin-bottom:72pt}@media print{body{font-size:12pt;line-height:18pt;margin-top:0pt;margin-bottom:0pt;font-family:"Times New Roman",Times,serif}p{margin-top:18pt;margin-bottom:0pt}p+p{text-indent:18pt}address,article,aside,audio,canvas,footer,header,ol,ul,dl,pre,section,table,video,img,figure{margin-top:18pt;margin-bottom:18pt}h1{font-size:21pt;line-height:36pt;margin-top:18pt;margin-bottom:18pt}h2{font-size:18pt;line-height:18pt;margin-top:18pt;margin-bottom:18pt}h3{font-size:16pt;line-height:18pt;margin-top:18pt;margin-bottom:18pt}h4{font-size:14pt;line-height:18pt;margin-top:18pt;margin-bottom:18pt}dt{margin-right:18pt}li{text-indent:18pt}blockquote{margin-top:27pt;margin-bottom:27pt;margin-left:27pt;margin-right:27pt}blockquote p{margin-top:0em;margin-bottom:0em;text-indent:0}figcaption{font-size:10pt;line-height:18pt;margin-top:0pt;margin-bottom:18pt}pre{white-space:pre-line}abbr[title]{border-bottom:0 none}small{font-size:10pt;line-height:18pt;margin-top:18pt;margin-bottom:18pt}hr{border-bottom:0.08333em solid #000;margin-top:17pt;margin-bottom:18pt}.note{font-size:10pt;line-height:18pt;margin-top:18pt;margin-bottom:18pt}}''' # noqa: E501 |
| 14 |
|
| 15 |
|
| 16 |
class InstapaperRecipe(BasicNewsRecipe): |
| 17 |
title = 'Instapaper' |
| 18 |
__author__ = 'Darko Miletic, Stanislav Khromov, Jim Ramsay, Stephan Hügel' |
| 19 |
publisher = 'Instapaper.com' |
| 20 |
publication_type = 'magazine' |
| 21 |
description = 'A digest of your unread Instapaper articles' |
| 22 |
compress_news_images_max_size = 250 |
| 23 |
category = 'info, custom, Instapaper' |
| 24 |
oldest_article = 365 |
| 25 |
max_articles_per_feed = 100 |
| 26 |
resolve_internal_links = True |
| 27 |
no_stylesheets = False |
| 28 |
timefmt = ' [%a, %d %b, %Y]' |
| 29 |
extra_css = gutenweb |
| 30 |
masthead_url = 'https://d2kfnvwohu0503.cloudfront.net/img/[email protected]' |
| 31 |
encoding = 'utf-8' |
| 32 |
language = 'en' |
| 33 |
remove_javascript = True |
| 34 |
|
| 35 |
recipe_specific_options = { |
| 36 |
'days': { |
| 37 |
'short': 'Oldest article to download from this news source. In days ', |
| 38 |
'long': 'For example, 0.5, gives you articles from the past 12 hours', |
| 39 |
'default': str(oldest_article), |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
def __init__(self, *args, **kwargs): |
| 44 |
BasicNewsRecipe.__init__(self, *args, **kwargs) |
| 45 |
d = self.recipe_specific_options.get('days') |
| 46 |
if d and isinstance(d, str): |
| 47 |
self.oldest_article = float(d) |
| 48 |
|
| 49 |
remove_tags = [ |
| 50 |
dict(name='div', attrs={'id': 'reflow'}), |
| 51 |
dict(name='div', attrs={'id': 'modal_backer'}), |
| 52 |
dict(name='div', attrs={'id': 'speedTimeRemaining'}), |
| 53 |
dict(name='div', attrs={'id': 'highlight_create_popover'}), |
| 54 |
dict(name='div', attrs={'id': 'highlight_delete_popover'}), |
| 55 |
dict(name='div', attrs={'id': 'summary_highlight_popover'}), |
| 56 |
dict(name='script'), |
| 57 |
dict(name='section', attrs={'class': 'primary_bar'}), |
| 58 |
dict(name='div', attrs={'class': 'modal_group'}), |
| 59 |
dict(name='div', attrs={'class': 'page_header_read'}), |
| 60 |
dict(name='div', attrs={'class': 'side_drawer_container'}), |
| 61 |
dict(name='div', attrs={'class': 'modal_name'}), |
| 62 |
dict(name='div', attrs={'class': 'highlight_popover'}), |
| 63 |
dict(name='div', attrs={'class': 'bar bottom'}), |
| 64 |
dict(name='div', attrs={'class': 'evernote_confirm'}), |
| 65 |
dict(name='div', attrs={'id': 'controlbar_container'}), |
| 66 |
dict(name='div', attrs={'id': 'footer'}), |
| 67 |
dict(name='div', attrs={'id': 'speedRead'}), |
| 68 |
dict(name='label'), |
| 69 |
] |
| 70 |
use_embedded_content = False |
| 71 |
needs_subscription = True |
| 72 |
INDEX = 'https://old.instapaper.com' |
| 73 |
LOGIN = INDEX + '/user/login' |
| 74 |
|
| 75 |
feeds = [('Instapaper Unread', 'https://old.instapaper.com/u')] |
| 76 |
remove_empty_feeds = True |
| 77 |
|
| 78 |
def get_browser(self): |
| 79 |
br = BasicNewsRecipe.get_browser(self) |
| 80 |
if self.username is not None: |
| 81 |
br.open(self.LOGIN) |
| 82 |
br.select_form(nr=0) |
| 83 |
br['username'] = self.username |
| 84 |
if self.password is not None: |
| 85 |
br['password'] = self.password |
| 86 |
br.submit() |
| 87 |
return br |
| 88 |
|
| 89 |
def parse_index(self): |
| 90 |
totalfeeds = [] |
| 91 |
lfeeds = self.get_feeds() |
| 92 |
for feedobj in lfeeds: |
| 93 |
feedtitle, feedurl = feedobj |
| 94 |
self.report_progress(0, 'Fetching feed' + ' %s...' % (feedtitle or feedurl)) |
| 95 |
articles = [] |
| 96 |
soup = self.index_to_soup(feedurl) |
| 97 |
for item in soup.findAll('a', attrs={'class': 'article_title'}): |
| 98 |
articles.append({ |
| 99 |
'url': 'https://old.instapaper.com' + item['href'], |
| 100 |
'title': item['title'], |
| 101 |
}) |
| 102 |
totalfeeds.append((feedtitle, articles)) |
| 103 |
return totalfeeds |