zbxcat/utils.py

30 lines
727 B
Python
Raw Normal View History

2017-05-22 18:00:34 -07:00
import hashlib
2017-05-23 11:22:21 -07:00
import json
2017-05-22 18:00:34 -07:00
def sha256(secret):
preimage = secret.encode('utf8')
h = hashlib.sha256(preimage).digest()
return h
# TODO: Port these over to leveldb or some other database
def save_trade(trade):
with open('xcat.json', 'w') as outfile:
json.dump(trade, outfile)
def get_trade():
with open('xcat.json') as data_file:
2017-05-23 13:34:48 -07:00
try:
xcatdb = json.load(data_file)
return xcatdb
except:
return None
def get_contract():
with open('contract.json') as data_file:
contractdb = json.load(data_file)
return contractdb
def save_contract(contracts):
with open('contract.json', 'w') as outfile:
json.dump(contracts, outfile)