-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
56 lines (46 loc) · 1.16 KB
/
main.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
55
56
import json
import time
from pprint import pprint
from mongo_settings import MONGO_SETTINGS
from mongoquery import MongoQuery
def example_callback(result):
data = json.loads(result)
# pprint(data['success'])
pprint(data)
if __name__ == '__main__':
query_client = MongoQuery(MONGO_SETTINGS)
# data = {
# "operation": "createView",
# "args": {
# "view": "specialized_tools_view",
# "collection": "onefloor_raw",
# "value": "工具"
# }
# }
data = '''
{
"operation": "select",
"args": {
"collection": "specialized_ddos_view",
"filter": {
"content": {
"$regex": "ddos"
}
},
"sort": {
"obtaintime": -1
},
"limit":10
}
}
'''
t1 = time.time()
# for i in range(1):
# 同步版本
# ret = json.loads(query_client.query(data))
# pprint(ret['success'])
# 异步回调版本
query_client.query(data, callback=example_callback)
query_client.threadpool.close()
query_client.threadpool.join()
pprint(time.time() - t1)