forked from itistheshortcut/message-board
-
Notifications
You must be signed in to change notification settings - Fork 0
/
func.py
51 lines (43 loc) · 1.54 KB
/
func.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
def read(data):
''
''' This function should receive a dictionary (see the json file format) and return a list of rows
For example:
data = {
"names": ["Son", "Thao"],
"posted_at": ["16/02/2020 22:37", "16/02/2020 22:39"],
"messages": ["Hello", "Hi"]
}
rows = [
("Son", "16/02/2020 22:37", "Hello"),
("Thao", "16/02/2020 22:39", "Hi")
]
Bonus: You might want to show the latest messages first. How would you do that?
'''
# Your code here
return rows
def write(rows, name, message):
from datetime import datetime
''' This function should receive a list of rows, a name and a message (string), and return a dictionary.
For example:
rows = [
("Thao", "16/02/2020 22:39", "Hi"),
("Son", "16/02/2020 22:37", "Hello")
]
name = "Anonymous"
message = "Hello world"
data = {
"names": ["Son", "Thao", "Anonymous"],
"posted_at": ["16/02/2020 22:37", "16/02/2020 22:39", "<current system date time>"],
"messages": ["Hello", "Hi", "Hello world"]
}
Note also the format of the date time should be the same as in the original data.
'''
# Your code here
return data
def checkLen(rows):
''
''' This function should return the length of rows.
We also want to show maximum 20 messages on our message board.
If there are more than 20 in the data file, you should show the 20 latest messages.
'''
# Your code here