edit task content; list content
This commit is contained in:
parent
2b48db5b62
commit
fe8dcce2b8
4 changed files with 104 additions and 39 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -101,3 +101,4 @@ ENV/
|
|||
.mypy_cache/
|
||||
|
||||
ztm.db
|
||||
tags
|
||||
|
|
9
model.py
9
model.py
|
@ -55,3 +55,12 @@ class Model:
|
|||
results = cursor.execute(query, (aid,))
|
||||
|
||||
return results.fetchone()
|
||||
|
||||
def save_content(self, aid, content):
|
||||
cursor = self.conn.cursor()
|
||||
cursor.execute('UPDATE task SET content=? WHERE aid=?', (content, aid))
|
||||
|
||||
self.conn.commit()
|
||||
query = '''
|
||||
UPDA
|
||||
'''
|
||||
|
|
8
tags
8
tags
|
@ -3,14 +3,15 @@ a /home/arnas/Skleps/ztm/ztm.py /^ a = Main()$/;" v language:Python
|
|||
Abcex /home/arnas/Skleps/ztm/model.py /^from abcex import Abcex$/;" i language:Python
|
||||
about /home/arnas/Skleps/ztm/ztm.py /^ def about(self):$/;" f language:Python
|
||||
add /home/arnas/Skleps/ztm/ztm.py /^ def add(self):$/;" f language:Python
|
||||
add_tag /home/arnas/Skleps/ztm/ztm.py /^ def add_tag(self, task_id):$/;" f language:Python
|
||||
bcolors /home/arnas/Skleps/ztm/bcolors.py /^class bcolors:$/;" c language:Python
|
||||
bcolors /home/arnas/Skleps/ztm/ztm.py /^from bcolors import bcolors$/;" i language:Python
|
||||
BOLD /home/arnas/Skleps/ztm/bcolors.py /^ BOLD = '\\033[1m'$/;" v language:Python class:bcolors
|
||||
bye /home/arnas/Skleps/ztm/ztm.py /^ def bye(self):$/;" f language:Python
|
||||
create_task_draft /home/arnas/Skleps/ztm/model.py /^ def create_task_draft(self, description):$/;" m language:Python class:Model
|
||||
edit_task /home/arnas/Skleps/ztm/ztm.py /^ def edit_task(self, aid):$/;" f language:Python
|
||||
ENDC /home/arnas/Skleps/ztm/bcolors.py /^ ENDC = '\\033[0m'$/;" v language:Python class:bcolors
|
||||
FAIL /home/arnas/Skleps/ztm/bcolors.py /^ FAIL = '\\033[91m'$/;" v language:Python class:bcolors
|
||||
fzfCall /home/arnas/Skleps/ztm/ztm.py /^ def fzfCall(self, elements):$/;" f language:Python
|
||||
FzfPrompt /home/arnas/Skleps/ztm/ztm.py /^from pyfzf.pyfzf import FzfPrompt$/;" i language:Python
|
||||
get_all_tasks /home/arnas/Skleps/ztm/model.py /^ def get_all_tasks(self):$/;" m language:Python class:Model
|
||||
get_task /home/arnas/Skleps/ztm/model.py /^ def get_task(self, aid):$/;" m language:Python class:Model
|
||||
get_tasks_by_tag /home/arnas/Skleps/ztm/model.py /^ def get_tasks_by_tag(self, tag_name):$/;" m language:Python class:Model
|
||||
|
@ -24,11 +25,14 @@ Model /home/arnas/Skleps/ztm/model.py /^class Model:$/;" c language:Python
|
|||
Model /home/arnas/Skleps/ztm/ztm.py /^from model import Model$/;" i language:Python
|
||||
OKBLUE /home/arnas/Skleps/ztm/bcolors.py /^ OKBLUE = '\\033[94m'$/;" v language:Python class:bcolors
|
||||
OKGREEN /home/arnas/Skleps/ztm/bcolors.py /^ OKGREEN = '\\033[92m'$/;" v language:Python class:bcolors
|
||||
re /home/arnas/Skleps/ztm/ztm.py /^import re$/;" i language:Python
|
||||
run /home/arnas/Skleps/ztm/ztm.py /^ def run(self):$/;" m language:Python class:Main
|
||||
save_content /home/arnas/Skleps/ztm/model.py /^ def save_content(self, aid, content):$/;" m language:Python class:Model
|
||||
search /home/arnas/Skleps/ztm/ztm.py /^ def search(self):$/;" f language:Python
|
||||
sqlite3 /home/arnas/Skleps/ztm/model.py /^import sqlite3$/;" i language:Python
|
||||
subprocess /home/arnas/Skleps/ztm/ztm.py /^import subprocess$/;" i language:Python
|
||||
sys /home/arnas/Skleps/ztm/ztm.py /^import sys$/;" i language:Python
|
||||
tempfile /home/arnas/Skleps/ztm/ztm.py /^import tempfile$/;" i language:Python
|
||||
UNDERLINE /home/arnas/Skleps/ztm/bcolors.py /^ UNDERLINE = '\\033[4m'$/;" v language:Python class:bcolors
|
||||
WARNING /home/arnas/Skleps/ztm/bcolors.py /^ WARNING = '\\033[93m'$/;" v language:Python class:bcolors
|
||||
__init__ /home/arnas/Skleps/ztm/model.py /^ def __init__(self):$/;" m language:Python class:Model
|
||||
|
|
125
ztm.py
125
ztm.py
|
@ -1,5 +1,9 @@
|
|||
import re
|
||||
import sys
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
from pyfzf.pyfzf import FzfPrompt
|
||||
|
||||
from model import Model
|
||||
from bcolors import bcolors
|
||||
|
@ -8,28 +12,32 @@ from bcolors import bcolors
|
|||
class Main:
|
||||
def __init__(self):
|
||||
self.model = Model()
|
||||
self.fzf = FzfPrompt()
|
||||
|
||||
def run(self):
|
||||
print('''
|
||||
_oo (o)__(o) \/
|
||||
>-(_ \(__ __) (OO)
|
||||
/ _/ ( ) ,'.--.)
|
||||
/ / )( / /|_|_\\
|
||||
/ ( ( )| \_.--.
|
||||
( `-. )/ '. \) \\
|
||||
`--.._) ( `-.(_.'
|
||||
print(bcolors.HEADER + '''
|
||||
GEEEEEEEL .. :
|
||||
,##############Wf.,;;L#K;;. ,W, .Et
|
||||
........jW##Wt t#E t##, ,W#t
|
||||
tW##Kt t#E L###, j###t
|
||||
tW##E; t#E .E#j##, G#fE#t
|
||||
tW##E; t#E ;WW; ##,:K#i E#t
|
||||
.fW##D, t#E j#E. ##f#W, E#t
|
||||
.f###D, t#E .D#L ###K: E#t
|
||||
.f####Gfffffffffff; t#E :K#t ##D. E#t
|
||||
.fLLLLLLLLLLLLLLLLLi fE ... #G ..
|
||||
: j
|
||||
|
||||
Task manager from Zordsdavini (2018)
|
||||
''')
|
||||
''' + bcolors.ENDC)
|
||||
|
||||
self.menu()
|
||||
|
||||
def menu(self):
|
||||
menu = input('What you want to do? (?+/tcq) ')
|
||||
menu = input(bcolors.OKGREEN + 'What you want to do? (?+/tcq) ' + bcolors.ENDC)
|
||||
|
||||
if menu == 'q':
|
||||
print('bye o/')
|
||||
sys.exit(0)
|
||||
self.bye()
|
||||
|
||||
elif menu == '?':
|
||||
self.about()
|
||||
|
@ -41,7 +49,7 @@ Task manager from Zordsdavini (2018)
|
|||
self.add()
|
||||
|
||||
def about(self):
|
||||
print('''
|
||||
print(bcolors.WARNING + '''
|
||||
Short instruction
|
||||
-----------------
|
||||
? - help (this dialog)
|
||||
|
@ -50,7 +58,7 @@ Short instruction
|
|||
t - tag manager
|
||||
c - configuration
|
||||
q - exit
|
||||
''')
|
||||
''' + bcolors.ENDC)
|
||||
self.menu()
|
||||
|
||||
def search(self):
|
||||
|
@ -61,9 +69,14 @@ q - exit
|
|||
tasksData = self.model.get_all_tasks()
|
||||
|
||||
for t in self.model.get_all_tasks():
|
||||
tasks.append('%s: %s' % (t[1], t[2]))
|
||||
tasks.append('%s: %s' % (t['aid'], t['description']))
|
||||
|
||||
selected = self.fzfCall(tasks)
|
||||
selected = self.fzf.prompt(tasks)
|
||||
if selected:
|
||||
m = re.search(r'^(.+):', selected[0])
|
||||
aid = m.group(1)
|
||||
if aid:
|
||||
self.edit_task(aid)
|
||||
|
||||
def add(self):
|
||||
print('\n' + bcolors.HEADER + 'Adding task\n' + bcolors.ENDC)
|
||||
|
@ -71,32 +84,34 @@ q - exit
|
|||
aid = self.model.create_task_draft(description)
|
||||
self.manage_task(aid)
|
||||
|
||||
|
||||
def add_tag(self, task_id):
|
||||
question = input('Do you want to add tag? ([y]/n) ')
|
||||
if question == 'y' or question == '':
|
||||
self.add_tag(task_id)
|
||||
pass
|
||||
|
||||
def manage_task(self, aid):
|
||||
task = self.model.get_task(aid)
|
||||
print('\n' + bcolors.HEADER + 'Managing: [' + task['aid'] + '] ' + task['description'] + '\n' + bcolors.ENDC)
|
||||
print('\n' + bcolors.HEADER + 'Managing: [' + task['aid'] + '] ' + task['description'] + bcolors.ENDC)
|
||||
|
||||
print('''
|
||||
#%s
|
||||
Description: %s
|
||||
Tags: [%s]
|
||||
Long Term: [%s]
|
||||
Created: %s
|
||||
''' % (task['aid'], task['description'], '', ' ', task['created_at']))
|
||||
|
||||
print()
|
||||
self.manage_task_menu(aid)
|
||||
|
||||
def manage_task_menu(self, aid):
|
||||
menu = input('What you want to do? (?e*+-v&q) ')
|
||||
menu = input(bcolors.OKGREEN + 'What you want to do? (?e*+-v&q) ' + bcolors.ENDC)
|
||||
|
||||
if menu == 'q':
|
||||
print('bye o/')
|
||||
sys.exit(0)
|
||||
self.bye()
|
||||
|
||||
elif menu == '?':
|
||||
self.manage_task_about(aid)
|
||||
|
||||
elif menu == 'e':
|
||||
self.edit_task(aid)
|
||||
|
||||
def manage_task_about(self, aid):
|
||||
print('''
|
||||
print(bcolors.WARNING + '''
|
||||
Short instruction
|
||||
-----------------
|
||||
? - help (this dialog)
|
||||
|
@ -107,16 +122,52 @@ e - edit content
|
|||
v - mark done
|
||||
& - add child task
|
||||
q - exit
|
||||
''')
|
||||
''' + bcolors.ENDC)
|
||||
self.manage_task_menu(aid)
|
||||
|
||||
def fzfCall(self, elements):
|
||||
try:
|
||||
p = subprocess.Popen(['echo', '\n'.join(elements)], stdout=subprocess.PIPE)
|
||||
p2 = subprocess.check_output(('fzf'), stdin=p.stdout)
|
||||
return p2
|
||||
except:
|
||||
return None
|
||||
def edit_task(self, aid):
|
||||
task = self.model.get_task(aid)
|
||||
|
||||
content = '''%s
|
||||
Tags: [%s]
|
||||
Long Term: [%s]
|
||||
Created: %s
|
||||
''' % (task['aid'], '', ' ', task['created_at'])
|
||||
|
||||
content += '\n# ' + task['description']
|
||||
if task['content']:
|
||||
content += task['content']
|
||||
|
||||
with tempfile.NamedTemporaryFile(suffix='.md', mode='r+') as temp:
|
||||
f = open(temp.name, 'r+')
|
||||
f.write(content)
|
||||
f.close()
|
||||
|
||||
subprocess.call(['vim', temp.name])
|
||||
|
||||
f = open(temp.name, 'r')
|
||||
new_content = f.read()
|
||||
f.close()
|
||||
|
||||
temp.close()
|
||||
|
||||
found = False
|
||||
content = ''
|
||||
for row in new_content.splitlines():
|
||||
if found:
|
||||
content += '\n' + row
|
||||
continue
|
||||
|
||||
if row == '# ' + task['description']:
|
||||
found = True
|
||||
|
||||
self.model.save_content(aid, content)
|
||||
print(bcolors.OKBLUE + '[content has been saved]/n' + bcolors.ENDC)
|
||||
self.manage_task(aid)
|
||||
|
||||
def bye(self):
|
||||
print(bcolors.FAIL + 'bye o/' + bcolors.ENDC)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Reference in a new issue