shadedb-api 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- shadedb_api/__init__.py +0 -0
- shadedb_api/console/__init__.py +33 -0
- shadedb_api/console/cli.py +206 -0
- shadedb_api/console/network/__init__.py +2 -0
- shadedb_api/console/network/connect.py +168 -0
- shadedb_api/frame/__init__.py +2 -0
- shadedb_api/frame/excepts.py +26 -0
- shadedb_api/frame/sync.py +76 -0
- shadedb_api-0.1.2.dist-info/METADATA +455 -0
- shadedb_api-0.1.2.dist-info/RECORD +14 -0
- shadedb_api-0.1.2.dist-info/WHEEL +5 -0
- shadedb_api-0.1.2.dist-info/entry_points.txt +3 -0
- shadedb_api-0.1.2.dist-info/licenses/LICENSE +674 -0
- shadedb_api-0.1.2.dist-info/top_level.txt +1 -0
shadedb_api/__init__.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#Dua for my late mum
|
|
2
|
+
#O Allah, forgive Latifat Temitope and elevate her station among those who are guided. Send her along the path of those who came before, and forgive us and her, O Lord of the worlds. Enlarge for her her grave and shed light upon her in it.
|
|
3
|
+
|
|
4
|
+
from shadeDB.core import shadeDB
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
base_path = Path(__file__).resolve().parents[1]
|
|
9
|
+
|
|
10
|
+
config_path = f"{base_path}/stored.scdb"
|
|
11
|
+
|
|
12
|
+
def __saver__():
|
|
13
|
+
try:
|
|
14
|
+
url = sys.argv[1]
|
|
15
|
+
token = sys.argv[2]
|
|
16
|
+
except IndexError:
|
|
17
|
+
print("""
|
|
18
|
+
shadedb-api-init endpoint token < missing arguments
|
|
19
|
+
""")
|
|
20
|
+
sys.exit()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
scdb = shadeDB(
|
|
24
|
+
file = config_path,
|
|
25
|
+
write = True,
|
|
26
|
+
id = False,
|
|
27
|
+
silent = True,
|
|
28
|
+
backup = False
|
|
29
|
+
)
|
|
30
|
+
scdb.update(("shadedb-api" , {"endpoint" : url, "token" : token }))
|
|
31
|
+
|
|
32
|
+
if __name__ == "__main__":
|
|
33
|
+
pass
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
from console.network.connect import shadeDB_cli
|
|
2
|
+
|
|
3
|
+
import textwrap,subprocess,json, sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
banner = """\x1b[1;34m
|
|
7
|
+
:+*:
|
|
8
|
+
.%%%%%%:
|
|
9
|
+
.#%%%%%%%%#.
|
|
10
|
+
-#%%%%%%%%%%%%*
|
|
11
|
+
-%%%%%%%%%%%%%%%%:
|
|
12
|
+
+%%%%%%%%%%%%%%%%% .= =
|
|
13
|
+
+#*%%%%%%%%%%%%* % -% % ++++. *++*.
|
|
14
|
+
+- :%%%%%%%%%#. % -% % ++-=+= *+:=+
|
|
15
|
+
+- #%%%%%%- % ###.-% ## :### .##:% ### += + *+ +-
|
|
16
|
+
+- .+%%: % :#:*#-%#:## %::*=.%%:*% *%:*# += *+*+==*
|
|
17
|
+
+%- =%% -#=- -% *% .-+#%-% .% %++=%-+= *+*+:=+.
|
|
18
|
+
+#*#- -%#+% =+%+-% *%.%*=#%-# % %====-+= +-*+ -+
|
|
19
|
+
+=:-*%: .*#*++% -# :%-% *%-% *%:%: *% %* .%:++..-+ *+ .*+
|
|
20
|
+
+=:::*%+ %#+++++% :#%%=-% *%.#%%%% %%%#% .%%%+ +++++ *++++
|
|
21
|
+
+=:::::+%%#++++++% .. . . .. . .. . ..
|
|
22
|
+
+=:::::::+++++++#*
|
|
23
|
+
#*::::::++++++*%
|
|
24
|
+
+%=::::++++#%+
|
|
25
|
+
*%+::++*%*
|
|
26
|
+
%%=+%#.
|
|
27
|
+
.%%.
|
|
28
|
+
\x1b[1;0m
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
class consoleApi:
|
|
32
|
+
def __init__(self, url:any= None, token:any=None):
|
|
33
|
+
self.url = url
|
|
34
|
+
self.token = token
|
|
35
|
+
self.db_name = None
|
|
36
|
+
|
|
37
|
+
if not self.url or not self.token:
|
|
38
|
+
if self.url:
|
|
39
|
+
print("\x1b[1;31mMissing keyword argument token\x1b[1;0m")
|
|
40
|
+
|
|
41
|
+
print("\x1b[1;31mMissing keyword argument url\x1b[1;0m")
|
|
42
|
+
|
|
43
|
+
self.communicate = shadeDB_cli(url = self.url, token = self.token)
|
|
44
|
+
|
|
45
|
+
def process_it(self,entered):
|
|
46
|
+
|
|
47
|
+
entered = entered.split("::",1)
|
|
48
|
+
if entered[0].lower() in ["insert"]:
|
|
49
|
+
e = self.communicate.context_manage_cli(command = entered[0], context = entered[1])
|
|
50
|
+
if isinstance(e,dict):
|
|
51
|
+
print(f"Database latency: {e.get("dbLatency","Not provided")}\n")
|
|
52
|
+
|
|
53
|
+
print(f"{e.get("result","Result missing")}")
|
|
54
|
+
else:
|
|
55
|
+
print(e)
|
|
56
|
+
elif entered[0].lower() in ["update"]:
|
|
57
|
+
s_part = entered[1].split("::")
|
|
58
|
+
jcd = entered[0] + "::" + s_part[:-1]
|
|
59
|
+
e = self.communicate.context_manage_cli(command = jcd, context = s_part[-1:])
|
|
60
|
+
if isinstance(e,dict):
|
|
61
|
+
print(f"Database latency: {e.get("dbLatency","Not provided")}\n")
|
|
62
|
+
|
|
63
|
+
print(f"{e.get("result","Result missing")}")
|
|
64
|
+
else:
|
|
65
|
+
print(e)
|
|
66
|
+
|
|
67
|
+
else:
|
|
68
|
+
jcd = entered[0] + "::" + entered[1]
|
|
69
|
+
e = self.communicate.general_cli(command = jcd)
|
|
70
|
+
if isinstance(e, dict):
|
|
71
|
+
print(f"Database latency: {e.get("dbLatency","Not provided")}\n")
|
|
72
|
+
|
|
73
|
+
print(f"{e.get("result","Result missing")}")
|
|
74
|
+
else:
|
|
75
|
+
print(e)
|
|
76
|
+
|
|
77
|
+
def console(self):
|
|
78
|
+
props = textwrap.dedent(f"""
|
|
79
|
+
|
|
80
|
+
\x1b[1;33mVersion: 0.1 MVP
|
|
81
|
+
Developer: shade
|
|
82
|
+
Github: harkerbyte [ https://github.com/harkerbyte ]
|
|
83
|
+
shadeDB 0.2.8: [ https://pypi.org/project/shadeDB ] 🥚: 98
|
|
84
|
+
|
|
85
|
+
\x1b[1;37m
|
|
86
|
+
Big thanks to the early adopters who’ve jumped on board.Our mission is locked in: building a high-velocity, self-managing database engine with a native, low-friction learning curve.\n
|
|
87
|
+
Forget "database babysitting"—we’re handling the infrastructure so you can get back to building the logic that actually matters.
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
""")
|
|
91
|
+
print(banner)
|
|
92
|
+
print(self.communicate.remote_status_cli())
|
|
93
|
+
print(props)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
while True:
|
|
97
|
+
entered = input("\n[\x1b[1;36mAPI\x1b[1;0m] $/ ")
|
|
98
|
+
if entered.strip() == "98":
|
|
99
|
+
subprocess.run(["xdg-open", "https://chat.whatsapp.com/IhFoE3IptShAzeCBKAkZNM?mode=gi_t"])
|
|
100
|
+
elif entered.strip().lower() == "console":
|
|
101
|
+
self.tweak_instance()
|
|
102
|
+
elif entered.strip().lower() == "exit":
|
|
103
|
+
return
|
|
104
|
+
else:
|
|
105
|
+
self.process_it(entered)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def tweak_instance(self):
|
|
109
|
+
self.db_name = self.communicate.db_name
|
|
110
|
+
while True:
|
|
111
|
+
try:
|
|
112
|
+
entered = input(f"\x1b[1;32m{"CONSOLE" if self.db_name is None else self.db_name.strip()}\x1b[1;0m $/ ").lower()
|
|
113
|
+
if entered.strip():
|
|
114
|
+
if entered == "exit":
|
|
115
|
+
break
|
|
116
|
+
if entered == "exit 2":
|
|
117
|
+
sys.exit()
|
|
118
|
+
if entered.strip() in ["info","information"]:
|
|
119
|
+
print(f"\x1b[1;37m{self.communicate.db_info_cli()}\x1b[1;0m")
|
|
120
|
+
else:
|
|
121
|
+
try:
|
|
122
|
+
part, part_ = entered.split("::",1)
|
|
123
|
+
if part.strip() == "name":
|
|
124
|
+
print(f"{self.communicate.db_name_change_cli(new_name = part_)}")
|
|
125
|
+
self.db_name = self.communicate.db_name
|
|
126
|
+
|
|
127
|
+
if part.strip() == "stat":
|
|
128
|
+
if part_.strip() == "volume":
|
|
129
|
+
print(f"{self.communicate.db_stat_volume_cli()}")
|
|
130
|
+
|
|
131
|
+
if "page" in part_.strip():
|
|
132
|
+
try:
|
|
133
|
+
cmd, paged = part_.split("::", 1)
|
|
134
|
+
print(f"\x1b[1;37m{self.communicate.db_pagination_cli(paging = paged)}\x1b[1;0m")
|
|
135
|
+
|
|
136
|
+
except (TypeError, ValueError):
|
|
137
|
+
print("\x1b[1;33mConsole: missing delimiter page :: (1,20)\x1b[1;0m")
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
if "unique" in part_.strip():
|
|
141
|
+
try:
|
|
142
|
+
cmd, new_unique = part_.split("::",1)
|
|
143
|
+
print(f"{self.communicate.db_unique_set_cli(new_unique)}")
|
|
144
|
+
|
|
145
|
+
except (TypeError , ValueError):
|
|
146
|
+
print(f"{self.communicate.db_uniques_cli()}")
|
|
147
|
+
|
|
148
|
+
if "cache" in part_.strip():
|
|
149
|
+
try:
|
|
150
|
+
cmd, status = part_.split("::",1)
|
|
151
|
+
if status.strip():
|
|
152
|
+
print(f"{self.communicate.db_cache_cli(set_to = status.strip())}")
|
|
153
|
+
|
|
154
|
+
except (TypeError,ValueError):
|
|
155
|
+
print("\x1b[1;33mConsole: missing delimiter cache :: activate / deactivate \x1b[1;0m")
|
|
156
|
+
|
|
157
|
+
if part_.strip() == "terminate":
|
|
158
|
+
stat = self.communicate.db_terminate_cli()
|
|
159
|
+
if "Deleted" in stat:
|
|
160
|
+
self.db_name = "Deleted"
|
|
161
|
+
self.communicate.db_name = "Deleted"
|
|
162
|
+
|
|
163
|
+
print(stat)
|
|
164
|
+
|
|
165
|
+
elif part.strip() == "snl":
|
|
166
|
+
self.process_it(part_)
|
|
167
|
+
|
|
168
|
+
except (TypeError, ValueError):
|
|
169
|
+
#print("\x1b[1;33mConsole: delimiter :: appears to be missing\x1b[1;0m")
|
|
170
|
+
pass
|
|
171
|
+
|
|
172
|
+
except Exception as e:
|
|
173
|
+
print(f"\x1b[1;31m{e}\x1b[1;0m")
|
|
174
|
+
|
|
175
|
+
except Exception as e:
|
|
176
|
+
print(f"\x1b[1;31m{e}\x1b[1;0m")
|
|
177
|
+
|
|
178
|
+
def __main__():
|
|
179
|
+
try:
|
|
180
|
+
url = sys.argv[1]
|
|
181
|
+
token = sys.argv[2]
|
|
182
|
+
client = consoleApi(url = url, token = token)
|
|
183
|
+
client.console()
|
|
184
|
+
except IndexError:
|
|
185
|
+
base_path = Path(__file__).resolve().parents[1]
|
|
186
|
+
|
|
187
|
+
config_path = f"{base_path}/stored.scdb"
|
|
188
|
+
|
|
189
|
+
from shadeDB.core import shadeDB
|
|
190
|
+
|
|
191
|
+
memory_resident = shadeDB(file = config_path)
|
|
192
|
+
config = memory_resident.get_context("shadedb-api")
|
|
193
|
+
config_url = config.get("endpoint", None)
|
|
194
|
+
config_token = config.get("token", None)
|
|
195
|
+
if not config_url:
|
|
196
|
+
print("shadedb-api-init endpoint < missing arguments")
|
|
197
|
+
sys.exit()
|
|
198
|
+
if not config_token:
|
|
199
|
+
print("shadedb-api-init endpoint token < missing arguments")
|
|
200
|
+
sys.exit()
|
|
201
|
+
|
|
202
|
+
client = consoleApi(url = config_url, token = config_token)
|
|
203
|
+
client.console()
|
|
204
|
+
|
|
205
|
+
if __name__ == "__main__":
|
|
206
|
+
pass
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import requests,json
|
|
2
|
+
|
|
3
|
+
class shadeDB_cli:
|
|
4
|
+
def __init__(self, url:str = None, token:str = None):
|
|
5
|
+
self.url = url
|
|
6
|
+
self.token = token
|
|
7
|
+
self.db_name = None
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def authenticator(self):
|
|
11
|
+
return {"dbToken" : self.token}
|
|
12
|
+
|
|
13
|
+
def remote_status_cli(self):
|
|
14
|
+
config = {"type" : "establish"}
|
|
15
|
+
config.update(self.authenticator())
|
|
16
|
+
try:
|
|
17
|
+
r = requests.post(self.url, json = config)
|
|
18
|
+
if r.status_code == 200:
|
|
19
|
+
self.db_name = r.json().get("dbName",None)
|
|
20
|
+
const = ""
|
|
21
|
+
for k,v in r.json().items():
|
|
22
|
+
if k == "Tier" or k == "Broadcast":
|
|
23
|
+
if v:
|
|
24
|
+
if "Reference error" not in v:
|
|
25
|
+
const += f"{k} : {v}\n"
|
|
26
|
+
|
|
27
|
+
return const
|
|
28
|
+
|
|
29
|
+
return f"[server ~ console]: Status code {r.status_code}"
|
|
30
|
+
except Exception as e:
|
|
31
|
+
return f"\x1b[1;31m{e}\x1b[1;0m"
|
|
32
|
+
|
|
33
|
+
def general_cli(self, command:str = None):
|
|
34
|
+
if command:
|
|
35
|
+
config = { "type" : "string", "command" : command }
|
|
36
|
+
auth_token = self.authenticator()
|
|
37
|
+
config.update(auth_token)
|
|
38
|
+
|
|
39
|
+
r = requests.post(self.url , json = config)
|
|
40
|
+
if r.status_code == 200:
|
|
41
|
+
return r.json()
|
|
42
|
+
|
|
43
|
+
elif r.status_code == 400:
|
|
44
|
+
return r.json().get("message", "Status code [400]: message missing.")
|
|
45
|
+
|
|
46
|
+
else:
|
|
47
|
+
return "Unexpected error"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def context_manage_cli(self, command:str = None, context:str|dict = None):
|
|
51
|
+
if command and context:
|
|
52
|
+
try:
|
|
53
|
+
if not isinstance(context,(str,dict)):
|
|
54
|
+
return "context must be str/dict"
|
|
55
|
+
|
|
56
|
+
if isinstance(context,str):
|
|
57
|
+
jsonString = context
|
|
58
|
+
else:
|
|
59
|
+
jsonString = json.dumps(context)
|
|
60
|
+
except json.JSONDecodeError as e:
|
|
61
|
+
raise e
|
|
62
|
+
finally:
|
|
63
|
+
auth_token = self.authenticator()
|
|
64
|
+
|
|
65
|
+
config = { "type" :"string/context", "command" : command, "context" : jsonString }
|
|
66
|
+
config.update(auth_token)
|
|
67
|
+
|
|
68
|
+
r = requests.post(self.url, json = config)
|
|
69
|
+
|
|
70
|
+
if r.status_code == 200:
|
|
71
|
+
return r.json()
|
|
72
|
+
|
|
73
|
+
elif r.status_code == 400:
|
|
74
|
+
return r.json().get("message", "Status code [400]: message missing.")
|
|
75
|
+
|
|
76
|
+
else:
|
|
77
|
+
return False
|
|
78
|
+
|
|
79
|
+
def db_name_change_cli(self,new_name:str=None):
|
|
80
|
+
config = {"type" : "nameChange", "name" : new_name}
|
|
81
|
+
config.update(self.authenticator())
|
|
82
|
+
|
|
83
|
+
re = requests.post(self.url, json = config, timeout = 5)
|
|
84
|
+
if re.status_code == 200:
|
|
85
|
+
self.db_name = re.json().get("database name","Not specified")
|
|
86
|
+
return re.json()
|
|
87
|
+
|
|
88
|
+
return f"[server ~ console]: Status code {re.status_code}"
|
|
89
|
+
|
|
90
|
+
def db_stat_volume_cli(self):
|
|
91
|
+
config = {"type" : "volume"}
|
|
92
|
+
config.update(self.authenticator())
|
|
93
|
+
re = requests.post(self.url, json = config, timeout = 5)
|
|
94
|
+
if re.status_code:
|
|
95
|
+
re = re.json()
|
|
96
|
+
return f"{re.get("volume", "Unable to retrieve volume")}"
|
|
97
|
+
|
|
98
|
+
return f"[server ~ console]: Status code {re.status_code}"
|
|
99
|
+
|
|
100
|
+
def db_pagination_cli(self, paging:str=None):
|
|
101
|
+
try:
|
|
102
|
+
start, finish = paging.split(",",1)
|
|
103
|
+
combp = [int(start),int(finish)]
|
|
104
|
+
config = {"type" : "pagination", "pageSize" : combp}
|
|
105
|
+
config.update(self.authenticator())
|
|
106
|
+
|
|
107
|
+
re = requests.post(self.url, json = config, timeout = 5)
|
|
108
|
+
if re.status_code == 200:
|
|
109
|
+
return f"[server ~ console]: {re.json()}"
|
|
110
|
+
|
|
111
|
+
return f"[server ~ console]: Status code {re.status_code}"
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
except (TypeError,ValueError):
|
|
115
|
+
return f"Console: Missing delimiter `,`"
|
|
116
|
+
|
|
117
|
+
def db_uniques_cli(self):
|
|
118
|
+
config = {"type" : "unique-get"}
|
|
119
|
+
config.update(self.authenticator())
|
|
120
|
+
re = requests.post(self.url, json = config, timeout = 5)
|
|
121
|
+
|
|
122
|
+
if re.status_code == 200:
|
|
123
|
+
return f"[server ~ console]: {re.json()}"
|
|
124
|
+
|
|
125
|
+
return f"[server ~ console]: Status code {re.status_code}"
|
|
126
|
+
|
|
127
|
+
def db_unique_set_cli(self, new_l:str=None):
|
|
128
|
+
config = {"type" : "unique-set", "newUniques" : new_l}
|
|
129
|
+
config.update(self.authenticator())
|
|
130
|
+
|
|
131
|
+
re = requests.post(self.url, json = config, timeout = 5)
|
|
132
|
+
if re.status_code == 200:
|
|
133
|
+
return re.json()
|
|
134
|
+
|
|
135
|
+
return f"[server ~ console]: Status code {re.status_code}"
|
|
136
|
+
|
|
137
|
+
def db_info_cli(self):
|
|
138
|
+
config = {"type" : "info"}
|
|
139
|
+
config.update(self.authenticator())
|
|
140
|
+
|
|
141
|
+
re = requests.post(self.url, json = config, timeout = 5)
|
|
142
|
+
if re.status_code == 200:
|
|
143
|
+
return re.json()
|
|
144
|
+
return f"[server ~ console]: Status code {re.status_code}"
|
|
145
|
+
|
|
146
|
+
def db_cache_cli(self,set_to:str=None):
|
|
147
|
+
if set_to:
|
|
148
|
+
config = {"type" : "cache", "setCache" : set_to.lower()}
|
|
149
|
+
config.update(self.authenticator())
|
|
150
|
+
|
|
151
|
+
re = requests.post(self.url, json = config, timeout = 5)
|
|
152
|
+
if re.status_code == 200:
|
|
153
|
+
return re.json()
|
|
154
|
+
|
|
155
|
+
return f"[server ~ console]: Status code {re.status_code}"
|
|
156
|
+
|
|
157
|
+
def db_terminate_cli(self):
|
|
158
|
+
config = {"type" : "terminate"}
|
|
159
|
+
config.update(self.authenticator())
|
|
160
|
+
|
|
161
|
+
re = requests.post(self.url, json = config)
|
|
162
|
+
if re.status_code == 200:
|
|
163
|
+
return re.json()
|
|
164
|
+
|
|
165
|
+
return f"[server ~ console]: Status code {re.status_code}"
|
|
166
|
+
|
|
167
|
+
if __name__ == "__main__":
|
|
168
|
+
print("Oops, nah")
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class URLEndpointMissingError(Exception):
|
|
2
|
+
"""Exception raised when the URL endpoint is missing."""
|
|
3
|
+
def __init__(self, source):
|
|
4
|
+
self.message = f"{source} missing endpoint url"
|
|
5
|
+
super().__init__(self.message)
|
|
6
|
+
|
|
7
|
+
class TokenMissingError(Exception):
|
|
8
|
+
"""Exception raised when the auth token is missing."""
|
|
9
|
+
def __init__(self, source):
|
|
10
|
+
self.message = f"{source} missing token"
|
|
11
|
+
super().__init__(self.message)
|
|
12
|
+
|
|
13
|
+
class SNLMissingError(Exception):
|
|
14
|
+
"""Exception raised when command is missing."""
|
|
15
|
+
def __init__(self, source):
|
|
16
|
+
self.message = f"command missing : {source}"
|
|
17
|
+
super().__init__(self.message)
|
|
18
|
+
|
|
19
|
+
class SNLContextMissingError(Exception):
|
|
20
|
+
"""Exception raised when dict context is missing."""
|
|
21
|
+
def __init__(self, source):
|
|
22
|
+
self.message = f"missing dictionary context : {source}"
|
|
23
|
+
super().__init__(self.message)
|
|
24
|
+
|
|
25
|
+
if __name__ == "__main__":
|
|
26
|
+
pass
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import requests, json
|
|
2
|
+
from frame.excepts import URLEndpointMissingError, TokenMissingError, SNLMissingError, SNLContextMissingError
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class syncFrame:
|
|
6
|
+
def __init__(self, endpoint:str=None, token:str|int=None, inspection:bool=False, query_timeout:int=None):
|
|
7
|
+
self.endpoint = endpoint
|
|
8
|
+
self.token = token
|
|
9
|
+
self.inspection = inspection
|
|
10
|
+
self.query_timeout = query_timeout
|
|
11
|
+
|
|
12
|
+
if not self.endpoint:
|
|
13
|
+
raise URLEndpointMissingError(self.endpoint)
|
|
14
|
+
|
|
15
|
+
if not self.token:
|
|
16
|
+
raise TokenMissingError(self.token)
|
|
17
|
+
|
|
18
|
+
def authenticator(self):
|
|
19
|
+
return {"dbToken" : self.token }
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def snlProcess(self, body):
|
|
23
|
+
default = {
|
|
24
|
+
"latency" : body.get("dbLatency",None),
|
|
25
|
+
"result" : body.get("result", "Result missing")
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
def snlQuery(self, command:str=None):
|
|
29
|
+
if not command:
|
|
30
|
+
raise SNLMissingError(self.snlQuery.__name__)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
config = { "type" : "string", "command" : command }
|
|
34
|
+
config.update(self.authenticator())
|
|
35
|
+
re = requests.post( self.endpoint, json = config, timeout = self.query_timeout if self.query_timeout != None else 20 )
|
|
36
|
+
if re.status_code == 200:
|
|
37
|
+
if not self.inspection:
|
|
38
|
+
return re.json().get("result", "Result missing")
|
|
39
|
+
else:
|
|
40
|
+
return self.snlProcess( body = re.json())
|
|
41
|
+
|
|
42
|
+
def processContext(body:dict=None):
|
|
43
|
+
if body:
|
|
44
|
+
try:
|
|
45
|
+
dicts = json.dumps(body)
|
|
46
|
+
return dicts
|
|
47
|
+
except Exception as e:
|
|
48
|
+
raise e
|
|
49
|
+
|
|
50
|
+
def snlComplexQuery(self, command:str=None, context:dict=None):
|
|
51
|
+
if not command:
|
|
52
|
+
raise SNLMissingError(self.snlComplexQuery.__name__)
|
|
53
|
+
|
|
54
|
+
if not context:
|
|
55
|
+
raise SNLContextMissingError(self.snlComplexQuery.__name__)
|
|
56
|
+
|
|
57
|
+
veri = processContext( body = context )
|
|
58
|
+
config = {
|
|
59
|
+
"type" : "string/context",
|
|
60
|
+
"context" : veri,
|
|
61
|
+
}
|
|
62
|
+
config.update(self.authenticator())
|
|
63
|
+
|
|
64
|
+
re = requests.post(self.endpoint, json = config, timeout = self.query_timeout if self.query_timeout != None else 20 )
|
|
65
|
+
|
|
66
|
+
if re.status_code == 200:
|
|
67
|
+
if not self.inspection:
|
|
68
|
+
return re.json().get("result", "Result missing")
|
|
69
|
+
else:
|
|
70
|
+
return self.snlProcess(body = re.json())
|
|
71
|
+
|
|
72
|
+
else:
|
|
73
|
+
re.status_code
|
|
74
|
+
|
|
75
|
+
if __name__ == "__main__":
|
|
76
|
+
pass
|