-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
41 lines (33 loc) · 891 Bytes
/
model.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
import json
import re
JSON_FILE = r".\static\bookmarks.json"
'''
Fetches bookmarks table
'''
def getBookmarks():
fp = open( JSON_FILE, 'r' )
table = json.load( fp )
fp.close()
return table
'''
Search Table of Bookmarks for specific tag
'''
def searchBookmarks( searchstring ):
table = []
fulltable = getBookmarks()
for entry in fulltable:
if searchstring.lower() in [ x.lower() for x in entry["Tags"] ]:
table.append( entry )
return table
'''
Add new bookmark to file
'''
def addBookmark( **bookmark ):
table = getBookmarks()
if bookmark["Link"].startswith( "http://") is False:
bookmark["Link"] = "http://" + bookmark["Link"]
bookmark["Tags"] = re.findall( r'\w+', bookmark["Tags"] )
table.append( bookmark )
fp = open( JSON_FILE, 'w' )
json.dump( table, fp )
fp.close()