-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnote.py
More file actions
27 lines (22 loc) · 994 Bytes
/
note.py
File metadata and controls
27 lines (22 loc) · 994 Bytes
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
import logging as log
import time
class Note:
def __init__(self, title: str, text: str, score=[], time=list(time.localtime(time.time()))):
if (not self.checkArgs(title, text, time, score)):
raise ValueError("Invalid note args.")
self.title = title
self.text = text
self.ctime = time
self.score = score
def checkArgs(self, title: str, text: str, ctime: list, score: list):
titleValid = type(title)==str and len(title)>0
textValid = type(text)==str
timeValid = type(ctime)==list and len(ctime)==9
scoreValid = type(score)==list
if (titleValid and textValid and timeValid and scoreValid):
return True
else:
log.error("Invalid note args. [%d %d %d %d]"%(titleValid, textValid, timeValid, scoreValid))
return False
def toDict(self):
return {"title": self.title, "text": self.text, "time": self.ctime, "score": self.score}