-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
71 lines (56 loc) · 1.95 KB
/
test.py
File metadata and controls
71 lines (56 loc) · 1.95 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from sbxpy.QueryBuilder import QueryBuilder as Qb
from sbxpy.__init__ import SbxCore as Sc
import asyncio
import os
from dotenv import load_dotenv
'''
This is a test using the os environment:
credentials app: APP-KEY, DOMAIN
credentials user: LOGIN, PASSWORD
'''
load_dotenv()
async def main(sci):
qb = Qb()
qb.set_domain(123)
qb.add_object({'user': 'data'})
print(qb.compile())
qb = Qb()
qb.set_domain(123)
qb.add_condition('AND', 'name', '=', 'pepe')
qb.add_condition('AND', 'edad', '>', 50)
qb.new_group('OR')
qb.add_condition('AND', 'genero', '=', 'M')
print(qb.compile())
# login = await sci.login(os.environ['LOGIN'], os.environ['PASSWORD'], os.environ['DOMAIN'])
# domain = await sci.list_domain()
sci.headers['Authorization'] = 'Bearer ' + os.environ['TOKEN']
all_data = await sci.with_model(os.environ["MODEL"]).find_all()
print("\n=== Prueba de find_all_generator ===\n")
async for page_data in sci.with_model(os.environ["MODEL"]).find_all_generator():
print(f"Número de registros en esta página: {len(page_data["results"])}")
return all_data
sc = Sc(manage_loop=True)
sc.initialize(os.environ['DOMAIN'], os.environ['APP-KEY'], os.environ['SERVER_URL'])
loop = asyncio.new_event_loop()
data = loop.run_until_complete(main(sc))
print(os.environ["MODEL"])
print(len(data["results"]))
if "fetched_results" in data:
for key in data["fetched_results"].keys():
print(key)
print(len(data["fetched_results"][key].keys()))
# def callback2(error, result):
# if error is not None:
# print(error)
# else:
# print(result)
# sc.close_connection()
#
# def callback(error, result):
# sc.with_model(os.environ['MODEL']).find_all_callback(callback2)
# if error is not None:
# print(error)
# else:
# print(result)
#sc.loginCallback(os.environ['LOGIN'], os.environ['PASSWORD'], os.environ['DOMAIN'],callback)
#loop.run_forever()