def crypto_spot(bot, trigger):
from_cur = trigger.group(1)
global last_prices
from_cur = from_cur.lower()
if from_cur not in main_coins:
bot.say("Invalid currency!")
api_result = requests.get(single_url.format(from_cur)).json()
if from_cur not in last_prices:
last_prices[from_cur] = 0
digits = False if from_cur.lower()=='xrp' else True
diffStr = getDiffString(float(api_result["last_price"]), last_prices[from_cur], digits)
last_prices[from_cur] = float(api_result["last_price"])
with open('~/.sopel/cur_py_cache', 'w') as outfile:
json.dump(last_prices, outfile)
bot.say("{0}: ${1:.{2}f}{3}".format(from_cur, float(api_result["last_price"]), 2 if digits else 4, diffStr))
评论列表
文章目录