2
2
import json
3
3
import pandas as pd
4
4
5
+
5
6
# Function to load notes from JSON file
6
7
def load_notes ():
7
- with open (' /notes.json' , 'r' ) as f :
8
+ with open (" /notes.json" , "r" ) as f :
8
9
return json .load (f )
9
10
11
+
10
12
# Function to save notes to JSON file
11
13
def save_notes (notes ):
12
- with open (' /notes.json' , 'w' ) as f :
14
+ with open (" /notes.json" , "w" ) as f :
13
15
json .dump (notes , f , indent = 4 )
14
16
17
+
15
18
# Load notes
16
19
notes = load_notes ()
17
20
@@ -32,9 +35,14 @@ def save_notes(notes):
32
35
"community" : ":people_holding_hands:" ,
33
36
# "code": ":code:",
34
37
"TEST" : ":science:" ,
35
- "architecture" : ":building_construction:"
38
+ "architecture" : ":building_construction:" ,
36
39
}
37
40
41
+ for note in notes :
42
+ for cat in note ["categories" ]:
43
+ if cat .lower () not in category_icon_map :
44
+ category_icon_map [cat .lower ()] = ":question:"
45
+
38
46
# Page selection
39
47
page = st .sidebar .selectbox ("Choose a page" , ["Home" , "Add Entry" ])
40
48
@@ -45,16 +53,20 @@ def save_notes(notes):
45
53
selected_categories = st .sidebar .multiselect (
46
54
"Select categories" ,
47
55
options = list (category_icon_map .keys ()),
48
- default = list (category_icon_map .keys ())
56
+ default = list (category_icon_map .keys ()),
49
57
)
50
58
51
59
# Filter notes based on selected categories
52
- filtered_notes = [note for note in notes if any (cat in note ['categories' ] for cat in selected_categories )]
60
+ filtered_notes = [
61
+ note
62
+ for note in notes
63
+ if any (cat in note ["categories" ] for cat in selected_categories )
64
+ ]
53
65
54
66
# Display filtered notes as tiles (3x wide)
55
67
tiles = []
56
68
for note in filtered_notes :
57
- icons = " " .join ([category_icon_map .get (cat , "" ) for cat in note [' categories' ]])
69
+ icons = " " .join ([category_icon_map .get (cat , "" ) for cat in note [" categories" ]])
58
70
tile_content = f"### { icons } { note ['title' ]} \n "
59
71
tile_content += f"[{ note ['link' ]} ]({ note ['link' ]} )\n "
60
72
tile_content += f"{ note ['description' ]} \n "
@@ -73,7 +85,7 @@ def save_notes(notes):
73
85
# Display filtered notes as a table, each category on its own row
74
86
st .write ("### Filtered Notes Table" )
75
87
for index , row in df .iterrows ():
76
- if any (cat in row [' categories' ] for cat in selected_categories ):
88
+ if any (cat in row [" categories" ] for cat in selected_categories ):
77
89
st .write (f"## { row ['title' ]} " )
78
90
st .markdown (f" - { row ['link' ]} " )
79
91
st .markdown (f" - { row ['description' ]} " )
@@ -103,7 +115,7 @@ def save_notes(notes):
103
115
"title" : new_title ,
104
116
"link" : new_link ,
105
117
"description" : new_description ,
106
- "categories" : selected_categories
118
+ "categories" : selected_categories ,
107
119
}
108
120
notes .append (new_entry )
109
121
save_notes (notes )
0 commit comments