-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnotebook.py
More file actions
66 lines (48 loc) · 1.4 KB
/
Copy pathnotebook.py
File metadata and controls
66 lines (48 loc) · 1.4 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
'''Build a notebook app
Primary objective -
learning OOP design concept
learning python syntax.'''
import datetime
last_page = 0
class Note:
'''Note object contains'
relevant tags and text
a match method provides lower
level of search.'''
def __init__(self, memo, tags):
self.tags = tags
self.memo = memo
self.date = datetime.date.today()
global last_page
last_page += 1
self.page = last_page
def match(self, filters):
return filters in self.memo or filters in self.tags
class Notebook():
'''Notebook is a collection
of Notes. methods to make notes,
find by page, search by tags and
to edit a note.'''
def __init__(self):
self.notes = []
def make_note(self, memo, tags):
self.notes.append(Note(memo, tags))
def _find_note(self, search_page):
if len(self.notes) < int(search_page):
return self.notes[search_page - 1]
return None
def modify_memo(self, search_id, memo):
note = self._find_note(search_id)
if note:
note.memo = memo
return True
return False
def modify_tags(self, search_id, tags):
note = self._find_note(search_id)
if note:
note.tags = tags
return True
return False
def search(self, filters):
return [note for note in self.notes
if note.match(filters)]