-
Notifications
You must be signed in to change notification settings - Fork 272
/
client_query.py
32 lines (25 loc) · 758 Bytes
/
client_query.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
@date: 2017-01-18
@author: Shell.Xu
@copyright: 2017, Eleme <zhixiang.xu@ele.me>
@license: MIT
'''
from __future__ import absolute_import, division,\
print_function, unicode_literals
import sys
import requests
BASEURL = 'http://localhost:6666'
def query(q, print_result=False):
resp = requests.post(BASEURL+'/query', params={'db': 'test', 'q': q})
return resp.status_code, resp.content
def main():
if len(sys.argv) == 1:
assert query('select * from cpu')[0] == 400
assert query('select value from cpu')[0] == 400
assert query('select value from cpu where time < now()')[0] == 200
else:
print(query(sys.argv[1])[1])
if __name__ == '__main__':
main()