Update Instapaper

This commit is contained in:
Kovid Goyal 2014-06-05 12:30:40 +05:30
parent 837cdcb95f
commit 93b6d39974

View File

@ -6,42 +6,39 @@
from calibre.web.feeds.news import BasicNewsRecipe from calibre.web.feeds.news import BasicNewsRecipe
class AdvancedUserRecipe1299694372(BasicNewsRecipe): class AdvancedUserRecipe1299694372(BasicNewsRecipe):
title = u'Instapaper' title = u'Instapaper'
__author__ = 'Darko Miletic, Stanislav Khromov, Jim Ramsay' __author__ = 'Darko Miletic, Stanislav Khromov, Jim Ramsay'
publisher = 'Instapaper.com' publisher = 'Instapaper.com'
category = 'info, custom, Instapaper' category = 'info, custom, Instapaper'
oldest_article = 365 oldest_article = 365
max_articles_per_feed = 100 max_articles_per_feed = 100
oldest_article = 0 reverse_article_order = True
no_stylesheets = False no_stylesheets = False
extra_css = 'q { font-style: italic; } .size3mode { color: black; }' extra_css = 'q { font-style: italic; } .size3mode { color: black; }'
remove_javascript = True remove_javascript = True
remove_tags = [ remove_tags = [
dict(name='div', attrs={'id':'text_controls_toggle'}) dict(name='div', attrs={'id':'text_controls_toggle'}),
,dict(name='script') dict(name='script'),
,dict(name='div', attrs={'id':'text_controls'}) dict(name='div', attrs={'id':'text_controls'}),
,dict(name='section', attrs={'class':'primary_bar'}) dict(name='section', attrs={'class':'primary_bar'}),
,dict(name='div', attrs={'class':'modal_group'}) dict(name='div', attrs={'class':'modal_group'}),
,dict(name='div', attrs={'id':'editing_controls'}) dict(name='div', attrs={'id':'editing_controls'}),
,dict(name='div', attrs={'class':'modal_name'}) dict(name='div', attrs={'class':'modal_name'}),
,dict(name='div', attrs={'class':'highlight_popover'}) dict(name='div', attrs={'class':'highlight_popover'}),
,dict(name='div', attrs={'class':'bar bottom'}) dict(name='div', attrs={'class':'bar bottom'}),
,dict(name='div', attrs={'id':'controlbar_container'}) dict(name='div', attrs={'id':'controlbar_container'}),
,dict(name='div', attrs={'id':'footer'}) dict(name='div', attrs={'id':'footer'}),
,dict(name='label') dict(name='label')
] ]
use_embedded_content = False use_embedded_content = False
needs_subscription = True needs_subscription = True
INDEX = u'http://www.instapaper.com' INDEX = u'http://www.instapaper.com'
LOGIN = INDEX + u'/user/login' LOGIN = INDEX + u'/user/login'
feeds = [ feeds = [
(u'Instapaper Unread', u'http://www.instapaper.com/u'), (u'Instapaper Unread', u'https://www.instapaper.com/u'),
(u'Instapaper Starred', u'http://www.instapaper.com/starred') (u'Instapaper Starred', u'http://www.instapaper.com/starred')
] ]
# Adds the title tag to the body of the recipe. Use this if your articles miss headings.
add_title_tag = False
def get_browser(self): def get_browser(self):
br = BasicNewsRecipe.get_browser(self) br = BasicNewsRecipe.get_browser(self)
@ -62,28 +59,13 @@ class AdvancedUserRecipe1299694372(BasicNewsRecipe):
self.report_progress(0, 'Fetching feed'+' %s...'%(feedtitle if feedtitle else feedurl)) self.report_progress(0, 'Fetching feed'+' %s...'%(feedtitle if feedtitle else feedurl))
articles = [] articles = []
soup = self.index_to_soup(feedurl) soup = self.index_to_soup(feedurl)
for item in soup.findAll('div', attrs={'class':'js_title_row title_row'}): for item in soup.findAll('a', attrs={'class': 'article_title'}):
# description = self.tag_to_string(item.div) articles.append({
atag = item.a 'url': item['href'],
if atag and 'href' in atag: 'title': item['title']
url = atag['href'] })
articles.append({
'url' :url
})
totalfeeds.append((feedtitle, articles)) totalfeeds.append((feedtitle, articles))
return totalfeeds return totalfeeds
def print_version(self, url): def print_version(self, url):
return 'http://www.instapaper.com' + url return 'http://www.instapaper.com' + url
def populate_article_metadata(self, article, soup, first):
article.title = soup.find('title').contents[0].strip()
def postprocess_html(self, soup, first_fetch):
# adds the title to each story, as it is not always included
if self.add_title_tag:
for link_tag in soup.findAll(attrs={"id" : "story"}):
link_tag.insert(0,'<h1>'+soup.find('title').contents[0].strip()+'</h1>')
# print repr(soup)
return soup