summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2016-12-09 20:50:18 +0100
committerYves Fischer <yvesf-git@xapek.org>2016-12-09 20:55:31 +0100
commit0d3a67d72dac49a17e8554a02f4763ae7c753c4f (patch)
tree7f7be1f6540f79ca65aa93d424cbc732d826ed92
parent8fad557345adb4d5181e3468df10c81b060ec0f1 (diff)
downloadwatchnews-0d3a67d72dac49a17e8554a02f4763ae7c753c4f.tar.gz
watchnews-0d3a67d72dac49a17e8554a02f4763ae7c753c4f.zip
cosmetic changes
- code reformat - .gitignore more files
-rw-r--r--.gitignore4
-rw-r--r--watchnews/web.py69
2 files changed, 33 insertions, 40 deletions
diff --git a/.gitignore b/.gitignore
index 9d458c7..74a6d86 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
__pycache__
-db.sqlite
+/*.sqlite
+/*.rss
+/.idea \ No newline at end of file
diff --git a/watchnews/web.py b/watchnews/web.py
index 2699554..721b4b6 100644
--- a/watchnews/web.py
+++ b/watchnews/web.py
@@ -1,16 +1,15 @@
from . import data, css
-from ll.xist import xsc, parse
-from ll.xist.ns import html, chars
+from ll.xist import xsc
+from ll.xist.ns import html
from flask import Flask, url_for
-import peewee
+import peewee as pw
import re
import difflib
class DiffSupport:
-
def __init__(self):
self.inline_style = False
@@ -25,8 +24,10 @@ class DiffSupport:
in_change = False
for ((line1, diff1), (line2, diff2), flag) in diff:
if flag ^ in_change:
- if flag: symbol = '↓'
- else: symbol = '↑'
+ if flag:
+ symbol = '↓'
+ else:
+ symbol = '↑'
rows.append(html.tr(html.td(' '.join(symbol * 10)),
html.td(' '.join(symbol * 10))))
in_change = flag
@@ -42,8 +43,8 @@ class DiffSupport:
'-': 'diff_sub',
'^': 'diff_chg'}
actionname = {
- '+': 'em',
- '-': 'em',
+ '+': 'strong',
+ '-': 'strong',
'^': 'strong'}
elems = []
nextpos = line.find('\x00')
@@ -60,7 +61,7 @@ class DiffSupport:
elems += [elem]
else:
elems += [html.span(text, **
- {'class': actionclass[line[nextpos + 1]]})]
+ {'class': actionclass[line[nextpos + 1]]})]
line = line[endpos:]
nextpos = line.find('\x00')
@@ -68,12 +69,11 @@ class DiffSupport:
if line != '': # trailing unchanged text
elems += [html.span(line)]
- elems += [ html.br() ]
+ elems += [html.br()]
return elems
class Difftable(html.div, DiffSupport):
-
def __init__(self, to_version, from_version=None, inline_style=False):
html.div.__init__(self)
DiffSupport.__init__(self)
@@ -86,11 +86,9 @@ class Difftable(html.div, DiffSupport):
def single_version(self, version):
self.append(html.table(
- html.tr(html.th('Title'), html.td(html.a(version.title,
- href=version.url))),
+ 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('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))
))
@@ -98,6 +96,7 @@ class Difftable(html.div, DiffSupport):
def two_versions(self, to_version, from_version):
def prepare_text(text):
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)
@@ -126,12 +125,10 @@ class Difftable(html.div, DiffSupport):
class ItemWidget(html.div, DiffSupport):
-
def __init__(self, item):
html.div.__init__(self)
DiffSupport.__init__(self)
- self.append(html.h2(html.a(item.title,
- href=url_for('item', id=item.id))))
+ self.append(html.h2(html.a(item.title, href=url_for('item', id=item.id))))
versionsFrom = [None] + list(item.versions)[:-1]
versionsTo = item.versions
versions = list(zip(versionsFrom, versionsTo))
@@ -153,7 +150,6 @@ class ItemWidget(html.div, DiffSupport):
class Template:
-
@staticmethod
def template(title, body):
return xsc.Frag(
@@ -163,14 +159,10 @@ class Template:
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',
html.body(body)))
@@ -182,7 +174,7 @@ class Template:
html.ul(
*map(lambda feed: html.li(
html.a(feed.title or feed.url, href=url_for('feed', id=feed.id))),
- feeds)))
+ feeds)))
@staticmethod
def feed(feed, items):
@@ -198,15 +190,13 @@ class Template:
versionsA = versions
versionsB = [None] + versions[:-1]
versions = list(zip(versionsA, versionsB))
- return Template.template('Item: {}'.format(item.title),
- html.div(
- 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(
- Difftable(versionAB[0], versionAB[1]),
- html.hr()),
- versions)))
+ return Template.template(
+ 'Item: {}'.format(item.title), html.div(
+ 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(
+ Difftable(versionAB[0], versionAB[1]),
+ html.hr()), versions)))
def get_app():
@@ -220,13 +210,14 @@ def get_app():
def feed(id):
feed = data.Feed.get(data.Feed.id == id)
counts = (data.Version.select(data.Version.item.alias('item_id'),
- peewee.fn.Count(data.Version.id).alias('count'))
+ pw.fn.Count(data.Version.id).alias('count'))
.group_by(data.Version.item)
.alias('counts'))
items = (data.Item.select()
.join(counts, on=(data.Item.id == counts.c.item_id))
- .where((data.Item.feed == feed) & (counts.c.count > 1))
+ .where((data.Item.feed == feed)
+ & (counts.c.count > 1))
.order_by(data.Item.created_date.desc()))
return Template.feed(feed, items).string('utf-8')