This commit is contained in:
Kovid Goyal 2013-05-29 08:01:36 +05:30
parent 3d699bb357
commit 826d5ab725
8 changed files with 173 additions and 172 deletions

View File

@ -85,7 +85,7 @@ class WeeklyLWN(BasicNewsRecipe):
while True:
curr = curr.findNext(attrs={'class': ['SummaryHL', 'Cat1HL', 'Cat2HL']})
if curr == None:
if curr is None:
break
text = curr.contents[0].string
@ -134,10 +134,11 @@ class WeeklyLWN(BasicNewsRecipe):
else:
print >>sys.stderr, "lwn_weekly.recipe: something bad happened; should not be able to reach this"
ans = [(section, articles[section]) for section in ans if section in articles]
ans = [(section2, articles[section2]) for section2 in ans if section2 in articles]
# from pprint import pprint
# pprint(ans)
return ans
# vim: expandtab:ts=4:sw=4

View File

@ -1,10 +1,11 @@
from calibre.web.feeds.news import BasicNewsRecipe
## History:
## 1: Base Version
## 2: Added rules for wdr.de, ndr.de, br-online.de
## 3: Added rules for rbb-online.de, boerse.ard.de, sportschau.de
## 4: New design of tagesschau.de implemented. Simplyfied.
## 5: Taken out the pictures.
import re
# History:
# 1: Base Version
# 2: Added rules for wdr.de, ndr.de, br-online.de
# 3: Added rules for rbb-online.de, boerse.ard.de, sportschau.de
# 4: New design of tagesschau.de implemented. Simplyfied.
# 5: Taken out the pictures.
class Tagesschau(BasicNewsRecipe):
title = 'Tagesschau'

View File

@ -114,7 +114,7 @@ class FB2Input(InputFormatPlugin):
break
opf = OPFCreator(os.getcwdu(), mi)
entries = [(f, guess_type(f)[0]) for f in os.listdir(u'.')]
entries = [(f2, guess_type(f)[0]) for f2 in os.listdir(u'.')]
opf.create_manifest(entries)
opf.create_spine([u'index.xhtml'])
if cpath:
@ -127,7 +127,7 @@ class FB2Input(InputFormatPlugin):
from calibre.ebooks.fb2 import base64_decode
self.binary_map = {}
for elem in doc.xpath('./*'):
if elem.text and 'binary' in elem.tag and elem.attrib.has_key('id'):
if elem.text and 'binary' in elem.tag and 'id' in elem.attrib:
ct = elem.get('content-type', '')
fname = elem.attrib['id']
ext = ct.rpartition('/')[-1].lower()
@ -146,3 +146,4 @@ class FB2Input(InputFormatPlugin):
with open(fname, 'wb') as f:
f.write(data)

View File

@ -105,8 +105,7 @@ class IndexEntry(object):
'author_offset': 71,
}
RTAG_MAP = {v:k for k, v in TAG_VALUES.iteritems()}
RTAG_MAP = {v:k for k, v in TAG_VALUES.iteritems()} # noqa
def __init__(self, offset, label_offset):
self.offset, self.label_offset = offset, label_offset
@ -131,8 +130,10 @@ class IndexEntry(object):
@dynamic_property
def size(self):
def fget(self): return self.length
def fset(self, val): self.length = val
def fget(self):
return self.length
def fset(self, val):
self.length = val
return property(fget=fget, fset=fset, doc='Alias for length')
@property
@ -383,7 +384,6 @@ class TBS(object): # {{{
buf.write(encode_tbs(last_article.index-next_sec.index,
{0b1000: 0}))
# If a section TOC starts and extends into the next record add
# a trailing vwi. We detect this by TBS type==3, processing last
# section present in the record, and the last article in that
@ -460,8 +460,10 @@ class Indexer(object): # {{{
for node in oeb.toc.iterdescendants():
if node.klass == 'article':
aut, desc = node.author, node.description
if not aut: aut = _('Unknown')
if not desc: desc = _('No details available')
if not aut:
aut = _('Unknown')
if not desc:
desc = _('No details available')
node.author, node.description = aut, desc
self.cncx = CNCX(oeb.toc, self.is_periodical)
@ -652,7 +654,6 @@ class Indexer(object): # {{{
next_offset = self.serializer.body_end_offset
index.length = next_offset - index.offset
# Remove empty indices
indices = [x for x in indices if x.length > 0]
@ -885,3 +886,4 @@ class Indexer(object): # {{{
# }}}

View File

@ -64,7 +64,8 @@ class Extract(ODF2XHTML):
f.write(css.encode('utf-8'))
def get_css_for_class(self, cls):
if not cls: return None
if not cls:
return None
for rule in self.css.cssRules.rulesOfType(CSSRule.STYLE_RULE):
for sel in rule.selectorList:
q = sel.selectorText
@ -112,7 +113,8 @@ class Extract(ODF2XHTML):
for img in imgpath(root):
div2 = img.getparent()
div1 = div2.getparent()
if (len(div1), len(div2)) != (1, 1): continue
if (len(div1), len(div2)) != (1, 1):
continue
cls = div1.get('class', '')
first_rules = filter(None, [self.get_css_for_class(x) for x in
cls.split()])
@ -151,7 +153,6 @@ class Extract(ODF2XHTML):
style = div2.attrib['style']
div2.attrib['style'] = 'display:inline;'+style
def filter_css(self, root, log):
style = root.xpath('//*[local-name() = "style" and @type="text/css"]')
if style:
@ -282,7 +283,7 @@ class Extract(ODF2XHTML):
zf = ZipFile(stream, 'r')
self.extract_pictures(zf)
opf = OPFCreator(os.path.abspath(os.getcwdu()), mi)
opf.create_manifest([(os.path.abspath(f), None) for f in
opf.create_manifest([(os.path.abspath(f2), None) for f2 in
walk(os.getcwdu())])
opf.create_spine([os.path.abspath('index.xhtml')])
with open('metadata.opf', 'wb') as f:
@ -291,3 +292,4 @@ class Extract(ODF2XHTML):

View File

@ -185,7 +185,7 @@ class DBAdder(QObject): # {{{
with open(cover, 'rb') as f:
cover = f.read()
orig_formats = formats
formats = [f for f in formats if not f.lower().endswith('.opf')]
formats = [f2 for f2 in formats if not f2.lower().endswith('.opf')]
if prefs['add_formats_to_existing']: # automerge is on
identical_book_list = self.db.find_identical_books(mi)
if identical_book_list: # books with same author and nearly same title exist in db
@ -385,7 +385,6 @@ class Adder(QObject): # {{{
if self.continue_updating:
single_shot(self.update)
def process_duplicates(self):
duplicates = self.db_adder.duplicates
if not duplicates:
@ -427,7 +426,6 @@ class Adder(QObject): # {{{
del self.db_adder
self.db_adder = None
@property
def number_of_books_added(self):
return getattr(getattr(self, 'db_adder', None), 'number_of_books_added',
@ -489,7 +487,6 @@ class Saver(QObject): # {{{
self.continue_updating = True
single_shot(self.update)
def canceled(self):
self.continue_updating = False
if self.worker is not None:
@ -499,7 +496,6 @@ class Saver(QObject): # {{{
self.callback(self.worker.path, self.failures, self.worker.error)
self.callback_called = True
def update(self):
if not self.continue_updating:
return
@ -531,7 +527,6 @@ class Saver(QObject): # {{{
self.get_result()
single_shot(self.update)
def get_result(self):
try:
id, title, ok, tb = self.rq.get_nowait()
@ -549,3 +544,4 @@ class Saver(QObject): # {{{
self.failures.add((title, tb))
# }}}

View File

@ -266,7 +266,7 @@ def dnd_get_files(md, exts):
remote_urls = [x for x in purls if x.scheme in ('http', 'https',
'ftp') and posixpath.splitext(x.path)[1][1:].lower() in exts]
if remote_urls:
filenames = [posixpath.basename(urllib.unquote(rurl.path)) for rurl in
filenames = [posixpath.basename(urllib.unquote(rurl2.path)) for rurl2 in
remote_urls]
return [urlunparse(x) for x in remote_urls], filenames
@ -336,3 +336,4 @@ def get_firefox_rurl(md, exts):
def has_firefox_ext(md, exts):
return bool(get_firefox_rurl(md, exts)[0])

View File

@ -2859,15 +2859,11 @@ class BibTeX:
def ValidateCitationKey(self, text):
"""
removes characters not allowed in BibTeX keys
>>> ValidateCitationKey(DummyEntry('my@id'))
'myid'
"""
return self.invalid_cit.sub(u'', text)
def braceUppercase(self, text):
""" Convert uppercase letters to bibtex encoded uppercase
>>> braceUppercase('Foo Bar')
'{F}oo {B}ar'
"""
return self.upper.sub(lambda m: u'{%s}' % m.group(), text)
@ -2906,3 +2902,4 @@ class BibTeX:
def bibtex_author_format(self, item):
# Format authors for Bibtex compliance (get a list as input)
return self.utf8ToBibtex(u' and '.join([author for author in item]))