From 4c2a9d256623360b34a37dbde19531919af41c21 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Mon, 23 Nov 2015 23:14:17 +0100 Subject: replace all " with ' --- watchnews/css.py | 20 ++++++------ watchnews/data.py | 4 +-- watchnews/fetch.py | 12 ++++---- watchnews/rss.py | 16 +++++----- watchnews/web.py | 89 ++++++++++++++++++++++++++---------------------------- watchnews/wsgi.py | 4 +-- 6 files changed, 71 insertions(+), 74 deletions(-) (limited to 'watchnews') diff --git a/watchnews/css.py b/watchnews/css.py index b32a274..825cd5e 100644 --- a/watchnews/css.py +++ b/watchnews/css.py @@ -10,20 +10,20 @@ class Rule: def _f(self, prop): key, value = prop - key = re.sub("([A-Z])", "-\\1", key).lower() - return " {}: {};".format(key, value) + key = re.sub('([A-Z])', '-\\1', key).lower() + return ' {}: {};'.format(key, value) def __format__(self): - result = " ".join(self.path) - result += " {\n" - result += "\n".join(map(self._f, self.properties.items())) - result += "\n}\n" + result = ' '.join(self.path) + result += ' {\n' + result += '\n'.join(map(self._f, self.properties.items())) + result += '\n}\n' return result def string(*rules): - return "\n".join(map(lambda r: r.__format__(), rules)) + return '\n'.join(map(lambda r: r.__format__(), rules)) -if __name__ == "__main__": - print("CSS Demo") - print(Rule(".foo", "#blah", backgroundColor="red").__format__()) +if __name__ == '__main__': + print('CSS Demo') + print(Rule('.foo', '#blah', backgroundColor='red').__format__()) diff --git a/watchnews/data.py b/watchnews/data.py index e4ecc24..125e3d1 100644 --- a/watchnews/data.py +++ b/watchnews/data.py @@ -26,8 +26,8 @@ class BaseModel(p.Model): def __json__(self): return self._data def __repr__(self): - return "<{.__class__.__name__} {}>".format(self, " ".join( - map(lambda kv: "{0[0]}={0[1]}".format(kv), self._data.items()))) + return '<{.__class__.__name__} {}>'.format(self, ' '.join( + map(lambda kv: '{0[0]}={0[1]}'.format(kv), self._data.items()))) class Feed(BaseModel): created_date = p.DateTimeField(default=datetime.datetime.now) diff --git a/watchnews/fetch.py b/watchnews/fetch.py index 5201c1e..e6c5c39 100755 --- a/watchnews/fetch.py +++ b/watchnews/fetch.py @@ -9,7 +9,7 @@ from newspaper.cleaners import DocumentCleaner import logging def update(feed): - logging.info("Update %s", feed.url) + logging.info('Update %s', feed.url) result = feedparser.parse(feed.url) if result['feed']['title'] != feed.title: feed.title = result['feed']['title'] @@ -44,7 +44,7 @@ def update(feed): version.url = entry['link'] authors = paper.authors authors.sort() - version.authors = ", ".join(authors) + version.authors = ', '.join(authors) version.title = paper.title version.text = paper.text @@ -64,7 +64,7 @@ def update(feed): version.text = text if len(version.text) < 2: # less than 2 chars is likely failure - raise Exception("failed to parse {}\n{}".format(entry,version)) + raise Exception('failed to parse {}\n{}'.format(entry,version)) # search if the previous version was the same ident_version = data.Version.select().where( @@ -74,10 +74,10 @@ def update(feed): (data.Version.text == version.text)).first() if ident_version: - logging.info("No change, skip %s", item.uid) + logging.info('No change, skip %s', item.uid) else: version.save() - logging.info("Saved new version of %s: %s", item.uid, version.id) + logging.info('Saved new version of %s: %s', item.uid, version.id) except Exception as e: - logging.exception("Failed to process %s", entry['link']) + logging.exception('Failed to process %s', entry['link']) diff --git a/watchnews/rss.py b/watchnews/rss.py index 30510c2..4ffa810 100644 --- a/watchnews/rss.py +++ b/watchnews/rss.py @@ -7,7 +7,7 @@ from ll.xist.ns import xml, rss20 def rss(): - versions = data.Version.raw("""\ + versions = data.Version.raw('''\ SELECT * FROM version v WHERE EXISTS (SELECT 1 @@ -16,7 +16,7 @@ WHERE EXISTS (SELECT 1 AND v2.item_id == v.item_id AND v2.created_date < v.created_date) ORDER BY v.created_date DESC -LIMIT 30""") +LIMIT 30''') items = [] for to_version in versions: @@ -28,14 +28,14 @@ LIMIT 30""") .first() difftable = Difftable(to_version, from_version, - inline_style=True).string("utf-8") + inline_style=True).string('utf-8') items.append(rss20.item( rss20.title( - "{} - {}".format(to_version.item.feed.title, to_version.title)), + '{} - {}'.format(to_version.item.feed.title, to_version.title)), rss20.author(to_version.authors), rss20.pubDate(to_version.created_date.strftime( - "%a, %d %b %Y %T %z")), - rss20.guid("from={},to={}".format(from_version.id, to_version.id)), + '%a, %d %b %Y %T %z')), + rss20.guid('from={},to={}'.format(from_version.id, to_version.id)), rss20.link(to_version.url), rss20.description( xsc.Text(difftable) @@ -43,8 +43,8 @@ LIMIT 30""") )) return xsc.Frag(xml.XML(), rss20.rss( rss20.channel( - rss20.title("Watchnews change report"), + rss20.title('Watchnews change report'), *items ) ) - ).string("utf-8") + ).string('utf-8') diff --git a/watchnews/web.py b/watchnews/web.py index b38f354..b212349 100644 --- a/watchnews/web.py +++ b/watchnews/web.py @@ -40,9 +40,9 @@ class DiffSupport: '-': 'em', '^': 'strong'} elems = [] - nextpos = line.find("\x00") + nextpos = line.find('\x00') while nextpos != -1 and nextpos + 1 < len(line): - endpos = line.find("\x01", nextpos + 2) + endpos = line.find('\x01', nextpos + 2) if nextpos != 0: # intermediate unchanged text elems += [html.span(line[:nextpos])] @@ -56,9 +56,9 @@ class DiffSupport: elems += [html.span(text, **{'class':actionclass[line[nextpos+1]]})] line = line[endpos:] - nextpos = line.find("\x00") + nextpos = line.find('\x00') - if line != "": # trailing unchanged text + if line != '': # trailing unchanged text elems += [html.span(line)] return elems @@ -68,7 +68,7 @@ class Difftable(html.div, DiffSupport): def __init__(self, to_version, from_version=None, inline_style=False): html.div.__init__(self) DiffSupport.__init__(self) - self.xmlname = "div" + self.xmlname = 'div' self.inline_style = inline_style if from_version == None: self.single_version(to_version) @@ -77,19 +77,18 @@ class Difftable(html.div, DiffSupport): def single_version(self, version): self.append(html.table( - html.tr(html.th("Title"), html.td(version.title)), - html.tr(html.th("Authors"), html.td(version.authors)), - html.tr(html.th("Date"), html.td( - version.created_date.strftime("%x %X"))), - html.tr(html.th("Link"), html.td( - html.a(version.url, href=version.url))), - html.tr(html.th("Text", colspan=2)), - html.tr(html.td(map(html.p, version.text.split("\n")), colspan=2)) + html.tr(html.th('Title'), html.td(html.a(version.title, + href=version.url))), + html.tr(html.th('Authors'), html.td(version.authors)), + html.tr(html.th('Date'), html.td( + version.created_date.strftime('%x %X'))), + html.tr(html.th('Text', colspan=2)), + html.tr(html.td(map(html.p, version.text.split('\n')), colspan=2)) )) def two_versions(self, to_version, from_version): def prepare_text(text): - return re.sub("\n\n\n*", "\n\n", text).split("\n") + return re.sub('\n\n\n*', '\n\n', text).split('\n') from_text = prepare_text(from_version.text) to_text = prepare_text(to_version.text) @@ -101,21 +100,19 @@ class Difftable(html.div, DiffSupport): diff = difflib._mdiff(from_text, to_text) self.append(html.div(html.table( - html.tr(html.th("Title"), - html.td(from_difftitle), - html.td(to_difftitle), **{'class': 'textdiff'}), - html.tr(html.th("Authors"), + html.tr(html.th('Title'), + html.td(html.a(from_difftitle, href=from_version.url)), + html.td(html.a(to_difftitle, href=to_version.url)), + **{'class': 'textdiff'}), + html.tr(html.th('Authors'), html.td(from_authors), html.td(to_authors), **{'class': 'textdiff'}), - html.tr(html.th("Date"), - html.td(from_version.created_date.strftime("%x %X")), - html.td(to_version.created_date.strftime("%x %X"))), - html.tr(html.th("Link"), - html.td(html.a(from_version.url, href=from_version.url)), - html.td(html.a(to_version.url, href=to_version.url))), - html.tr(html.th("Text", colspan=3))), + html.tr(html.th('Date'), + html.td(from_version.created_date.strftime('%x %X')), + html.td(to_version.created_date.strftime('%x %X'))), + html.tr(html.th('Text', colspan=3))), self._diff_lines(from_text, to_text), - **{'class': "versiondiff"} + **{'class': 'versiondiff'} )) @@ -141,8 +138,8 @@ class ItemWidget(html.div, DiffSupport): from_difftitle, to_difftitle = self._diff( from_version.title, to_version.title) title = html.span(to_difftitle, **{'class': 'textdiff'}) - return html.li(html.span(to_version.created_date.strftime("%x %X")), - html.span(" - "), + return html.li(html.span(to_version.created_date.strftime('%x %X')), + html.span(' - '), title) @@ -151,28 +148,28 @@ class Template: @staticmethod def template(title, body): return xsc.Frag( - html.DocTypeXHTML10transitional(), "\n", + html.DocTypeXHTML10transitional(), '\n', html.html( html.head( html.meta(charset='utf-8'), html.title(title), html.style(css.string( - css.Rule(".textdiff", ".diff_add", - backgroundColor="#CEF6CE"), - css.Rule(".textdiff", ".diff_next", - backgroundColor="#c0c0c0"), - css.Rule(".textdiff", ".diff_sub", - backgroundColor="#FFDADA"), - css.Rule(".textdiff", ".diff_chg", - backgroundColor="#E5E1FF") + css.Rule('.textdiff', '.diff_add', + backgroundColor='#CEF6CE'), + css.Rule('.textdiff', '.diff_next', + backgroundColor='#c0c0c0'), + css.Rule('.textdiff', '.diff_sub', + backgroundColor='#FFDADA'), + css.Rule('.textdiff', '.diff_chg', + backgroundColor='#E5E1FF') )) - ), "\n", + ), '\n', html.body(body))) @staticmethod def index(feeds): return Template.template( - "Index", + 'Index', html.ul( *map(lambda feed: html.li( html.a(feed.title or feed.url, href=url_for('feed', id=feed.id))), @@ -181,9 +178,9 @@ class Template: @staticmethod def feed(feed, items): return Template.template( - "Feed {}".format(feed.title or feed.url), + 'Feed {}'.format(feed.title or feed.url), html.div( - html.a("Back", href=url_for('index')), + html.a('Back', href=url_for('index')), html.h1(feed.title), *map(ItemWidget, items))) @@ -192,9 +189,9 @@ class Template: versionsA = versions versionsB = [None] + versions[:-1] versions = list(zip(versionsA, versionsB)) - return Template.template("Item: {}".format(item.title), + return Template.template('Item: {}'.format(item.title), html.div( - html.a("Back to {}".format(item.feed.title), + html.a('Back to {}'.format(item.feed.title), href=url_for('feed', id=item.feed.id)), html.h1(item.title), *map(lambda versionAB: html.div( @@ -208,7 +205,7 @@ def get_app(): @app.route('/') def index(): - return Template.index(data.Feed.select()).string("utf-8") + return Template.index(data.Feed.select()).string('utf-8') @app.route('/feed/') def feed(id): @@ -216,7 +213,7 @@ def get_app(): items = data.Item.select() \ .where(data.Item.feed == feed) \ .order_by(data.Item.created_date.desc()) - return Template.feed(feed, items).string("utf-8") + return Template.feed(feed, items).string('utf-8') @app.route('/item/') def item(id): @@ -224,7 +221,7 @@ def get_app(): versions = data.Version.select() \ .where(data.Version.item == item) \ .order_by(data.Version.created_date) - return Template.item(item, list(versions)).string("utf-8") + return Template.item(item, list(versions)).string('utf-8') return app diff --git a/watchnews/wsgi.py b/watchnews/wsgi.py index bd157cb..1a5240b 100644 --- a/watchnews/wsgi.py +++ b/watchnews/wsgi.py @@ -2,9 +2,9 @@ from watchnews import web, data import os -dbpath = os.environ.get("WATCHNEWS_DBPATH") +dbpath = os.environ.get('WATCHNEWS_DBPATH') if not dbpath: - raise Exception("WATCHNEWS_DBPATH must be set") + raise Exception('WATCHNEWS_DBPATH must be set') data.init_sqlite(dbpath) application = web.get_app() -- cgit v1.2.1