-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcall2api.py
120 lines (96 loc) · 3.13 KB
/
call2api.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from requests import post
from json import dumps
from xxhash import xxh32
from db import *
global url_pre
url_pre = 'http://127.0.0.1:1111/'
def hash(text):
text = str(text)
return xxh32(text).hexdigest()
def call(api_url, data, pre=True):
if pre:
response = post(url_pre + api_url, data=dumps(data))
else:
response = post(api_url, data=dumps(data))
print(response.status_code)
print(response.text)
return response.text.replace('"', '')
def user_in_db(token, id=None, tg=None, ds=None, mine=None, nick=None):
data = {'token': token}
if id:
data['id'] = id
elif tg:
data['tg'] = str(tg)
elif ds:
data['ds'] = str(ds)
elif mine:
data['mine'] = mine
elif nick:
data['nick'] = nick
#print(data)
return call('api/user_in_db/', data)
def user_add(token, nick, passwd, tg=None, ds=None, mine=None):
passwd = hash(passwd)
data = {'token': token, 'nick': nick, 'passwd': passwd}
if tg:
data['tg'] = str(tg)
if ds:
data['ds'] = str(ds)
if mine:
data['mine'] = mine
print(data)
return call('api/user_add/', data)
def user_del(token, id):
data = {'token': token, 'id': id}
return call('api/user_del/', data)
def coins_add(token, id, amount):
data = {'token': token, 'id': id, 'amount': amount}
return call('api/coins_add/', data)
def coins_del(token, id, amount):
data = {'token': token, 'id': id, 'amount': amount}
return call('api/coins_del/', data)
def coins_transfer(token, src_id, dst_id, amount):
data = {'token': token, 'src_id': src_id, 'dst_id': dst_id, 'amount': amount}
return call('api/coins_transfer/', data)
def update_tg(token, id, tg):
if tg != None:
data = {'token': token, 'id': id, 'tg': str(tg)}
else:
data = {'token': token, 'id': id, 'tg': None}
return call('api/update_tg/', data)
def update_ds(token, id, ds):
data = {'token': token, 'id': id, 'ds': str(ds)}
return call('api/update_ds/', data)
def update_mine(token, id, mine):
data = {'token': token, 'id': id, 'mine': str(mine)}
return call('api/update_mine/', data)
def update_nick(token, id, nick):
data = {'token': token, 'id': id, 'nick': nick}
return call('api/update_nick/', data)
def update_passwd(token, id, passwd):
data = {'token': token, 'id': id, 'passwd': hash(passwd)}
return call('api/update_passwd/', data)
def check_bal(token, id):
data = {'token': token, 'id': id}
return call('api/check_bal/', data)
def get_nick(token, id):
data = {'token': token, 'id': id}
return call('api/get_nick/', data)
def get_tg(token, id):
data = {'token': token, 'id': id}
return call('api/get_tg/', data)
def get_ds(token, id):
data = {'token': token, 'id': id}
return call('api/get_ds/', data)
def get_mine(token, id):
data = {'token': token, 'id': id}
return call('api/get_mine/', data)
def get_passwd(token, id):
data = {'token': token, 'id': id}
return call('api/get_passwd/', data)
def transfer_callback(addr, token, src_nick, dst_nick, amount):
amount = str(amount)
data = {'token': token, 'src_nick': src_nick, 'dst_nick': dst_nick, 'amount': amount}
print(addr + 'api/transfer_callback/')
return call(addr + 'api/transfer_callback/', data, pre=False)
#print( user_in_db('ee77b9d8-44f3-4e01-a702-69d5524ee50b', '1234') )