2024-07-18 15:34:40 +00:00
|
|
|
from requests import post
|
2024-11-01 10:52:57 +00:00
|
|
|
from json import dumps, loads
|
2024-07-18 15:34:40 +00:00
|
|
|
from xxhash import xxh32
|
|
|
|
|
|
|
|
from db import *
|
|
|
|
|
|
|
|
global url_pre
|
2024-07-27 16:35:14 +00:00
|
|
|
url_pre = 'http://127.0.0.1:7001/'
|
2024-07-18 15:34:40 +00:00
|
|
|
|
|
|
|
def hash(text):
|
|
|
|
text = str(text)
|
|
|
|
return xxh32(text).hexdigest()
|
|
|
|
|
2024-11-01 10:52:57 +00:00
|
|
|
def call(api_url, data, pre=True, fix=True):
|
2024-07-26 20:01:00 +00:00
|
|
|
if pre:
|
|
|
|
response = post(url_pre + api_url, data=dumps(data))
|
|
|
|
else:
|
|
|
|
response = post(api_url, data=dumps(data))
|
2024-11-01 10:52:57 +00:00
|
|
|
#print(response.status_code)
|
|
|
|
#print(response.text)
|
|
|
|
try:
|
|
|
|
if fix:
|
|
|
|
return response.text.replace('"', '')
|
|
|
|
else:
|
|
|
|
return response.text
|
|
|
|
except:
|
|
|
|
return response.text
|
2024-07-18 15:34:40 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2024-12-01 14:34:58 +00:00
|
|
|
def add_user(token, nick, passwd, tg=None, ds=None, mine=None):
|
2024-07-18 15:34:40 +00:00
|
|
|
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)
|
2024-12-01 14:34:58 +00:00
|
|
|
return call('api/add_user/', data)
|
2024-07-18 15:34:40 +00:00
|
|
|
|
2024-12-01 14:34:58 +00:00
|
|
|
def del_user(token, id):
|
2024-07-18 15:34:40 +00:00
|
|
|
data = {'token': token, 'id': id}
|
2024-12-01 14:34:58 +00:00
|
|
|
return call('api/del_user/', data)
|
2024-07-18 15:34:40 +00:00
|
|
|
|
2024-12-01 14:34:58 +00:00
|
|
|
def add_coins(token, id, amount):
|
2024-07-18 15:34:40 +00:00
|
|
|
data = {'token': token, 'id': id, 'amount': amount}
|
2024-12-01 14:34:58 +00:00
|
|
|
return call('api/add_coins/', data)
|
2024-07-18 15:34:40 +00:00
|
|
|
|
2024-12-01 14:34:58 +00:00
|
|
|
def del_coins(token, id, amount):
|
2024-07-18 15:34:40 +00:00
|
|
|
data = {'token': token, 'id': id, 'amount': amount}
|
2024-12-01 14:34:58 +00:00
|
|
|
return call('api/del_coins/', data)
|
2024-07-18 15:34:40 +00:00
|
|
|
|
2024-12-01 14:34:58 +00:00
|
|
|
def transfer_coins(token, src_id, dst_id, amount):
|
2024-07-18 15:34:40 +00:00
|
|
|
data = {'token': token, 'src_id': src_id, 'dst_id': dst_id, 'amount': amount}
|
2024-12-01 14:34:58 +00:00
|
|
|
return call('api/transfer_coins/', data)
|
2024-07-18 15:34:40 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2024-11-01 10:52:57 +00:00
|
|
|
def update_time(token, id, time):
|
|
|
|
data = {'token': token, 'id': id, 'time': time}
|
|
|
|
return call('api/update_time/', data)
|
|
|
|
|
2024-07-18 15:34:40 +00:00
|
|
|
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):
|
2024-11-01 10:52:57 +00:00
|
|
|
data = {'token': token, 'id': id}
|
|
|
|
return call('api/get_tg/', data)
|
2024-07-18 15:34:40 +00:00
|
|
|
|
|
|
|
def get_ds(token, id):
|
2024-11-01 10:52:57 +00:00
|
|
|
data = {'token': token, 'id': id}
|
|
|
|
return call('api/get_ds/', data)
|
2024-07-18 15:34:40 +00:00
|
|
|
|
|
|
|
def get_mine(token, id):
|
2024-11-01 10:52:57 +00:00
|
|
|
data = {'token': token, 'id': id}
|
|
|
|
return call('api/get_mine/', data)
|
2024-07-18 15:34:40 +00:00
|
|
|
|
|
|
|
def get_passwd(token, id):
|
2024-11-01 10:52:57 +00:00
|
|
|
data = {'token': token, 'id': id}
|
|
|
|
return call('api/get_passwd/', data)
|
|
|
|
|
2024-11-29 09:10:01 +00:00
|
|
|
def get_time2cdm(token, id):
|
2024-11-01 10:52:57 +00:00
|
|
|
data = {'token': token, 'id': id}
|
2024-11-29 09:10:01 +00:00
|
|
|
return call('api/get_time2cdm/', data)
|
2024-11-01 10:52:57 +00:00
|
|
|
|
2024-12-01 14:34:58 +00:00
|
|
|
def get_stat(token, date = None):
|
2024-11-01 10:52:57 +00:00
|
|
|
data = {'token': token}
|
2024-12-01 14:34:58 +00:00
|
|
|
if date:
|
|
|
|
data['date'] = date
|
2024-11-01 10:52:57 +00:00
|
|
|
return loads(call('api/get_stat/', data, fix=False))
|
2024-07-18 15:34:40 +00:00
|
|
|
|
2024-07-26 20:01:00 +00:00
|
|
|
def transfer_callback(addr, token, src_nick, dst_nick, amount):
|
2024-07-24 13:37:08 +00:00
|
|
|
amount = str(amount)
|
2024-07-26 20:01:00 +00:00
|
|
|
data = {'token': token, 'src_nick': src_nick, 'dst_nick': dst_nick, 'amount': amount}
|
|
|
|
return call(addr + 'api/transfer_callback/', data, pre=False)
|
2024-07-24 13:37:08 +00:00
|
|
|
|
2024-12-01 14:34:58 +00:00
|
|
|
def gen_token(token, id):
|
2024-11-30 05:45:14 +00:00
|
|
|
data = {'token': token, 'id': id}
|
2024-12-01 14:34:58 +00:00
|
|
|
return call('api/gen_token/', data)
|
|
|
|
|
|
|
|
def gen_fp_mess(token, nick, amount, chat_id, fp_id):
|
|
|
|
data = {'token': token, 'nick': nick, 'amount': amount, 'chat_id': chat_id, 'fp_id': fp_id}
|
|
|
|
return call('http://127.0.0.1:7002/api/gen_fp_mess/', data, pre=False)
|
|
|
|
|
|
|
|
def list_fp(token, id):
|
|
|
|
data = {'token': token, 'id': id}
|
|
|
|
return call('api/list_fp/', data)
|
|
|
|
|
|
|
|
def gen_fp(token, id, amount):
|
|
|
|
data = {'token': token, 'id': id, 'amount': amount}
|
|
|
|
return call('api/gen_fp/', data)
|
|
|
|
|
|
|
|
def del_fp(token, fp_id):
|
|
|
|
data = {'token': token, 'fp_id': fp_id}
|
|
|
|
return call('api/del_fp/', data)
|
2024-11-30 05:45:14 +00:00
|
|
|
|
2024-11-30 09:51:14 +00:00
|
|
|
|
2024-07-18 15:34:40 +00:00
|
|
|
#print( user_in_db('ee77b9d8-44f3-4e01-a702-69d5524ee50b', '1234') )
|