From e3496045ef68b1e83e5570b2608f14b2fcdb49f2 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 21 Jul 2017 19:32:11 +0200 Subject: added web style --- lib/classes.py | 6 ++- lib/commands.py | 7 ++-- lib/templates/index.html | 95 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/web.py | 12 ++++++ 4 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 lib/templates/index.html create mode 100644 lib/web.py diff --git a/lib/classes.py b/lib/classes.py index 50f3e14..9370241 100644 --- a/lib/classes.py +++ b/lib/classes.py @@ -1,6 +1,10 @@ import redis, socket, os -from config import config as co +try: + from .config import config as co +except: + from config import config as co + r = redis.Redis(host=co['host'], port=co['port'], unix_socket_path=co['unix_socket_path'], db=co['db']) def clear(): diff --git a/lib/commands.py b/lib/commands.py index 45789f1..c61d698 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -101,10 +101,10 @@ class Commands(object): print('nessun todo con questo id') else: try: - msg = msgFromId(cmd[1]) #return value of sorted set's rank + msg = self.msgFromId(cmd[1]) #return value of sorted set's rank r.zrem('todo', msg) r.decr('idTODO') - print('Ok %s' % msg) + print('Ok') except: print('0') except IndexError: @@ -112,8 +112,7 @@ class Commands(object): except KeyError: ListCommands.err('keyword') - @staticmethod - def msgFromId(value): + def msgFromId(self, value): for i, val in enumerate(r.zrange('todo', 0, -1)): if i == int(value): return val.decode('utf-8') diff --git a/lib/templates/index.html b/lib/templates/index.html new file mode 100644 index 0000000..e7c47b5 --- /dev/null +++ b/lib/templates/index.html @@ -0,0 +1,95 @@ + + + + Stout · check TODO list thank to Redis + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ {% if len_todo == 0 %} +

+
+ nessun todo in lista: goditi una Stout!!!

+ {% endif %} + {% for i in list_todo %} +
+

{{ i.decode('utf-8') }}

+
+ {% endfor %} +
+ + diff --git a/lib/web.py b/lib/web.py new file mode 100644 index 0000000..69522f8 --- /dev/null +++ b/lib/web.py @@ -0,0 +1,12 @@ +from flask import Flask, render_template +from .classes import r + +app = Flask(__name__) + +@app.route("/") +def hello(): + lista = r.zrange('todo', 0, -1) + try: + return render_template("index.html", list_todo = lista, len_todo = len(lista)) + except Exception as e: + return 'errore: %s' % e -- cgit v1.2.3-18-g5258