-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistmanagerLib.py
134 lines (83 loc) · 3.75 KB
/
listmanagerLib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import datahandler
from dataclasses import dataclass
import prompts
from listmanager import Csvpackage
@dataclass
class IsKeyword():
isKeyWord:bool
word:str
def entryFinder(listOfEntries:list[datahandler.ListElem], id) -> datahandler.ListElem:
for i in listOfEntries:
if i.id == id:
return i
return None
def isKeywordWrapper(cmd, keyword) -> IsKeyword:
if (cmd == keyword):
return IsKeyword(True, cmd)
return IsKeyword(False, cmd)
def printEntries(list:list[datahandler.ListElem]):
for ent in list:
print(f" <> id={ent.id} | {ent.deadline} | {ent.content}")
def changeStatus(srcFile, dstFile):
id = isKeywordWrapper(input(prompts.idPrompt), prompts.abortKeyword)
if(id.isKeyWord):
return
list_elem = deleteEntryFromId(srcFile, id.word)
datahandler.csvInterfacer(dstFile, datahandler.writeRowToList(list_elem), 'a')
def deleteEntryFromId(file, id) -> datahandler.ListElem:
list = datahandler.csvInterfacer(file, datahandler.readFromList(), 'r')
list_elem = entryFinder(list, id)
list.remove(list_elem)
datahandler.csvInterfacer(file, datahandler.deleteList(), 'w')
datahandler.csvInterfacer(file, datahandler.writeRowsToList(list), 'a')
return list_elem
def list_all(csvpackage:Csvpackage):
l_todo = datahandler.csvInterfacer(csvpackage.csvtodo, datahandler.readFromList(), 'r')
l_done = datahandler.csvInterfacer(csvpackage.csvdone, datahandler.readFromList(), 'r')
printEntries(l_todo)
print(prompts.lineSeperator)
printEntries(l_done)
def list_done(csvpackage:Csvpackage):
l_done = datahandler.csvInterfacer(csvpackage.csvdone, datahandler.readFromList(), 'r')
printEntries(l_done)
def list_todo(csvpackage:Csvpackage):
l_todo = datahandler.csvInterfacer(csvpackage.csvtodo, datahandler.readFromList(), 'r')
printEntries(l_todo)
def insert(csvpackage:Csvpackage):
l_todo = datahandler.csvInterfacer(csvpackage.csvtodo, datahandler.readFromList(), 'r')
l_done = datahandler.csvInterfacer(csvpackage.csvdone, datahandler.readFromList(), 'r')
validID = False
while(not validID):
id = isKeywordWrapper(input(prompts.idPrompt), prompts.abortKeyword)
if(id.isKeyWord) :
return
if (entryFinder(l_todo, id.word) != None or entryFinder(l_done, id.word) != None):
print(prompts.insertIDnotValid)
continue
validID = True
deadline = isKeywordWrapper(input(prompts.deadlinePrompt), prompts.abortKeyword)
if(deadline.isKeyWord):
return
content = isKeywordWrapper(input(prompts.contentPrompt), prompts.abortKeyword)
if(content.isKeyWord):
return
datahandler.csvInterfacer(csvpackage.csvtodo, datahandler.writeRowToList(datahandler.ListElem(id.word, deadline.word, content.word)), 'a')
def did(csvpackage:Csvpackage):
changeStatus(csvpackage.csvtodo, csvpackage.csvdone)
def undid(csvpackage:Csvpackage):
changeStatus(csvpackage.csvdone, csvpackage.csvtodo)
def delete_todo(csvpackage:Csvpackage):
id = isKeywordWrapper(input(prompts.idPrompt), prompts.abortKeyword)
if(id.isKeyWord):
return
deleteEntryFromId(csvpackage.csvtodo, id.word)
def delete_done(csvpackage:Csvpackage):
id = isKeywordWrapper(input(prompts.idPrompt), prompts.abortKeyword)
if(id.isKeyWord):
return
deleteEntryFromId(csvpackage.csvdone, id.word)
def init(csvpackage:Csvpackage):
print(prompts.initWarning)
if(isKeywordWrapper(input(prompts.typeConfirmWarning), prompts.confirmKeyword).isKeyWord):
datahandler.csvInterfacer(csvpackage.csvtodo, datahandler.deleteList(), 'w')
datahandler.csvInterfacer(csvpackage.csvdone, datahandler.deleteList(), 'w')