-
Notifications
You must be signed in to change notification settings - Fork 1
/
nipo.py
101 lines (87 loc) · 2.1 KB
/
nipo.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import conn
class Config():
def __init__(self, token, server, port):
self.token = token
self.server = server
self.port = port
def CreateConfig(token, server, port):
global conf
conf = Config(token, server, port )
def CreateConnection() :
global sock
sock = conn.NipoSocket()
def OpenConnection( ):
CreateConnection()
sock.connect(conf.server, conf.port)
def Ping():
OpenConnection()
string = conf.token+" "+"ping"
connection = sock.send(string)
ok = False
if connection:
ok = True
sock.close()
return(connection.decode() , ok)
def Status():
OpenConnection()
string = conf.token+" "+"status"
connection = sock.send(string)
ok = False
if connection:
ok = True
sock.close()
return(connection.decode(), ok)
def Set(key, value):
OpenConnection()
string = conf.token+" set "+key+" "+value
connection = sock.send(string)
ok = False
if connection:
ok = True
sock.close()
return(connection.decode() , ok)
def Get(key):
OpenConnection()
string = conf.token+" get "+key
connection = sock.send(string)
ok = False
if connection:
ok = True
sock.close()
return(connection.decode() , ok)
def Select(key):
OpenConnection()
string = conf.token+" select "+key
connection = sock.send(string)
ok = False
if connection:
ok = True
sock.close()
return(connection.decode() , ok)
def Avg(key):
OpenConnection()
string = conf.token+" avg "+key
connection = sock.send(string)
ok = False
if connection:
ok = True
sock.close()
return(connection.decode() , ok)
def Sum(key):
OpenConnection()
string = conf.token+" sum "+key
connection = sock.send(string)
ok = False
if connection:
ok = True
sock.close()
return(connection.decode() , ok)
def Count(key):
OpenConnection()
string = conf.token+" count "+key
connection = sock.send(string)
ok = False
if connection:
ok = True
sock.close()
return(connection.decode() , ok)