-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
46 lines (36 loc) · 955 Bytes
/
db.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
from tinydb import TinyDB, where
db = TinyDB('db/db.json')
# Insert into database
def db_insert(name, ticker):
exist = db_search_ticker(ticker)
if not exist:
before = len(db)
db.insert({'name': name, 'ticker': ticker})
after = len(db)
if (after > before):
return True
else:
return False
else:
return False
# Delete from database
def db_delete(ticker):
exist = db_search_ticker(ticker)
if exist:
before = len(db)
db.remove(where('ticker') == ticker)
after = len(db)
if (before > after):
return True
else:
return False
else:
return False
# Search name in database
def db_search_name(name):
result = db.search(where('name') == name)
return result
# Search ticker in database
def db_search_ticker(ticker):
result = db.search(where('ticker') == ticker)
return result