-
Notifications
You must be signed in to change notification settings - Fork 0
/
motion_database.py
54 lines (45 loc) · 1.31 KB
/
motion_database.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
52
53
54
import json
import os
class MotionDB(object):
def __init__(self , location):
self.location = os.path.expanduser(location)
self.load(self.location)
def load(self , location):
if os.path.exists(location):
self._load()
else:
self.db = {}
return True
def _load(self):
self.db = json.load(open(self.location , "r"))
def dumpdb(self):
try:
json.dump(self.db , open(self.location, "w+"))
return True
except:
return False
def set(self , key , value):
try:
self.db[str(key)] = value
self.dumpdb()
return True
except Exception as e:
print("[X] Error Saving Values to Database : " + str(e))
return False
def get(self , key):
try:
return self.db[key]
except KeyError:
print("No Value Can Be Found for " + str(key))
return False
def delete(self , key):
if not key in self.db:
return False
del self.db[key]
self.dumpdb()
return True
def resetdb(self):
self.db={}
self.dumpdb()
return True
MotionDB('/Users/successerviceofothers/ML_VU/connectors/python/motion_primitives_dir/motionkeys.json')