From 182971e61b582d784025643a22f7b8de40fa2c31 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 22 Aug 2017 11:23:28 +0200 Subject: fixed 'get todo' --- lib/.app.py.swp | Bin 0 -> 12288 bytes lib/.commands.py.swp | Bin 16384 -> 20480 bytes lib/app.py | 7 ++++--- lib/commands.py | 16 +++++++++++++--- 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 lib/.app.py.swp diff --git a/lib/.app.py.swp b/lib/.app.py.swp new file mode 100644 index 0000000..7aa2759 Binary files /dev/null and b/lib/.app.py.swp differ diff --git a/lib/.commands.py.swp b/lib/.commands.py.swp index 9ca6f3b..adf7a25 100644 Binary files a/lib/.commands.py.swp and b/lib/.commands.py.swp differ diff --git a/lib/app.py b/lib/app.py index 1a74485..c3ec9a7 100644 --- a/lib/app.py +++ b/lib/app.py @@ -2,6 +2,7 @@ from classes import r, clear, YELLOW, BLACK, GREY from commands import Commands from listcommands import ListCommands import os.path +from config import config class Stout(Commands): @@ -22,7 +23,7 @@ class Stout(Commands): if users exists, return username, else return an empty string """ try: - with open('/tmp/stout', 'rb') as fin: + with open(config['path'], 'rb') as fin: user = fin.readline() if user == '': @@ -69,8 +70,8 @@ if __name__ == '__main__': app = Stout() cmd = '' - if not os.path.isfile('/tmp/stout'): - open('/tmp/stout', 'wb').close() + if not os.path.isfile(config['path']): + open(config['path'], 'wb').close() while cmd != 'quit': try: diff --git a/lib/commands.py b/lib/commands.py index 10c89fb..eaeaf98 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -19,7 +19,7 @@ class Commands(object): self.user = cmd[2] - with open('/tmp/stout', 'wb') as fout: + with open(co['path'], 'wb') as fout: fout.write(cmd[2].encode('utf-8')) print('Ok') @@ -38,7 +38,8 @@ class Commands(object): if cmd[2] == 'user': #if self.user is empty, print 'nil' if self.user != '': - print(r.get('user').decode('utf-8')) + with open(co['path'], 'rb') as fin: + print(fin.readline().decode('utf-8')) else: print('nil') elif cmd[2] not in ListCommands.commands['get'][1]: #check if the word after 'i' exists @@ -46,7 +47,16 @@ class Commands(object): else: print(co[cmd[2]]) elif cmd[1] == 'todo': - todolist = r.zrange('todo', 0, -1) + with open(co['path'], 'rb') as fout: + try: + lines = fout.readlines() + except: + lines = '' + + if lines is not None: + todolist = [x.strip() for i, x in enumerate(lines) if i > 0] + else: + todolist = [] if len(todolist) == 0: #if todo is empty print('nessun todo in lista: goditi una Stout') -- cgit v1.2.3-18-g5258