Fixed top and xmr

This commit is contained in:
root 2018-01-27 15:22:42 +00:00
parent 6af75e9049
commit 8da04665ca
1 changed files with 36 additions and 42 deletions

View File

@ -375,32 +375,27 @@ def cmc(bot, trigger):
@sopel.module.commands('top') @sopel.module.commands('top')
def top(bot, trigger): def top(bot, trigger):
if not trigger.group(2): topXstring = ""
bot.say("You want to see the CMC top... how many? Pick a number 1 through 20")
else:
try: try:
try:
r = requests.get('https://api.coinmarketcap.com/v1/global/')
j = r.json()
usd_total_mkt_cap = float(j['total_market_cap_usd'])
total_mcap_short = int(int(round(usd_total_mkt_cap,-9))/int(1e9))
rounded_total_mcap = str(total_mcap_short)+"B"
topXstring += "Total market cap $" + rounded_total_mcap + " | "
except:
bot.say("Can't connect to coinmarketcap API")
if not trigger.group(2):
limit = 20
else:
limit = int(trigger.group(2)) limit = int(trigger.group(2))
if limit > 20: if limit > 20:
bot.say("Too high! Max is 20!") bot.say("Too high! Max is 20!")
elif limit < 1: elif limit < 1:
bot.say("Dude...") bot.say("Dude...")
else:
topXstring = ""
try:
r = requests.get('https://api.coinmarketcap.com/v1/global/')
j = r.json()
usd_total_mkt_cap = float(j[0]['total_market_cap_usd'])
total_mcap_short = int(int(round(usd_total_mkt_cap,-9))/int(1e9)
rounded_total_mcap = str(total_mcap_short)+"B"
topXstring += "Total market cap $" + rounded_total_mcap + " | "
except:
bot.say("Can't connect to coinmarketcap API")
try:
r = requests.get('https://api.coinmarketcap.com/v1/ticker?limit={}'.format(limit)) r = requests.get('https://api.coinmarketcap.com/v1/ticker?limit={}'.format(limit))
j = r.json() j = r.json()
except:
bot.say("Can't connect to API")
for i in j: for i in j:
symbol = i['symbol'] symbol = i['symbol']
name = i['name'] name = i['name']
@ -641,13 +636,12 @@ def xmrtall(bot, trigger):
bot.say("Something borked ¤\( `⌂´ )/¤") bot.say("Something borked ¤\( `⌂´ )/¤")
# Binance # Binance
try: try:
r = requests.get(binanceurl) r = requests.get(binanceurl)
j = r.json() j = r.json()
found = False found = False
for i in j: for i in j:
if i["symbol"] == XMR+BTC: if i["symbol"] == "XMRBTC":
last=float(i['lastPrice']) last=float(i['lastPrice'])
vol=float(i['volume']) vol=float(i['volume'])
stringtosend += ("Binance last: {0:.6f} on {1:.2f} BTC volume |".format(last, vol*last)) stringtosend += ("Binance last: {0:.6f} on {1:.2f} BTC volume |".format(last, vol*last))