-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotesapp_põhi.py
More file actions
104 lines (83 loc) · 2.82 KB
/
Copy pathnotesapp_põhi.py
File metadata and controls
104 lines (83 loc) · 2.82 KB
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
import json
import os
from datetime import datetime
from notesapp_gui import start_gui
Demo = False
print(f'''
* * * NotesApp * * *
Demo mode: {'On' if Demo else 'Off'}
Timestamp: {datetime.now().isoformat()}
''')
Note_faili_nimi = 'Demo/demo.notid.json' if Demo else 'Notid/notid.json'
class Notid:
def __init__(self,Fail_nimi=Note_faili_nimi):
self.Fail_nimi = Fail_nimi
self.notid= []
self.next_id = 1
self.loe_notid()
Viimati_muudetud_aeg = datetime.now().isoformat()
# Failidega tegelemine
def loe_notid(self):
if not os.path.exists(self.Fail_nimi):
self.notid = []
self.next_id = 1
return
with open(self.Fail_nimi,'r',encoding='utf-8') as f:
data = json.load(f)
self.notid = data.get('notes', [])
self.next_id = data.get('next_id',1)
# Salvesta notid faili
def salvesta_notid(self):
dirpath = os.path.dirname(self.Fail_nimi)
if dirpath:
os.makedirs(dirpath, exist_ok=True)
data = {
'notes': self.notid,
'next_id': self.next_id
}
with open(self.Fail_nimi, 'w', encoding= 'utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=2)
# Lisa uus note
def lisa_note(self,title,body):
note = {
'id': self.next_id,
'title': title,
'body': body,
'timestamp': datetime.now().isoformat()
}
self.notid.append(note)
self.next_id += 1
self.salvesta_notid()
return note
# Muuda note-i
def muuda_note(self, note_id, title, body, update_timestamp=True):
"""
Muuda olemasolevat märget.
If `update_timestamp` is False, the note's timestamp will not be modified.
"""
for note in self.notid:
if note['id'] == note_id:
note['title'] = title
note['body'] = body
if update_timestamp:
note['timestamp'] = datetime.now().isoformat()
self.salvesta_notid()
return note
return None
def leia_note_by_id(self, note_id):
for note in self.notid:
if note['id'] == note_id:
return note
# Kustuta note id järgi
def kustuta_note(self,note_id):
self.notid = [note for note in self.notid if note['id'] != note_id]
self.salvesta_notid()
# Listi kõik notid
def noti_list(self):
return[{'id': note['id'], 'title': note['title'], 'timestamp': note['timestamp']} for note in self.notid]
# Callib GUI faili, et seda käivitada
def main():
manager = Notid()
start_gui(manager)
if __name__ == "__main__":
main()