top working now

This commit is contained in:
root 2018-01-03 15:58:02 +00:00
parent b134ca3625
commit 8298297c37
1 changed files with 29 additions and 37 deletions

View File

@ -362,43 +362,35 @@ def top(bot, trigger):
if not trigger.group(2): if not trigger.group(2):
bot.say("You want to see the CMC top... how many? Pick a number 1 through 10") bot.say("You want to see the CMC top... how many? Pick a number 1 through 10")
else: else:
if type(trigger.group(2)) in (float, int): try:
limit = int(trigger.group(2)) limit = int(trigger.group(2))
mylist = range(1,limit + 1) if limit > 10:
if limit > 10: bot.say("Too high! Max is 10!")
bot.say("Too high! Max is 10!") elif limit < 1:
elif limit < 1: bot.say("Dude...")
bot.say("Dude...") else:
else: try:
try: r = requests.get('https://api.coinmarketcap.com/v1/ticker?limit={}'.format(limit))
r = requests.get('https://api.coinmarketcap.com/v1/ticker?limit=50') j = r.json()
j = r.json() except:
except: bot.say("Can't connect to API")
bot.say("Can't connect to API") topXstring = ""
try: for i in j:
for therank in mylist: symbol = i['symbol']
for i in j: name = i['name']
try: rank = i['rank']
if i['rank'] == str(therank): price_usd = float(i['price_usd'])
coin = i price_btc = float(i['price_btc'])
except: pass market_cap_usd = float(i['market_cap_usd'])
symbol = coin['symbol'] if market_cap_usd >= 1000000000:
name = coin['name'] market_cap_short = int(int(round(market_cap_usd,-9))/int(1000000000))
rank = coin['rank'] rounded_mcap = str(market_cap_short)+"B"
price_usd = float(coin['price_usd']) else:
price_btc = float(coin['price_btc']) rounded_mcap = "tiny"
market_cap_usd = float(coin['market_cap_usd']) topXstring += "{0}. {1} ${2} | ".format(rank, symbol, rounded_mcap) #TODO: add price_usd, rounded
if market_cap_usd >= 1000000000: bot.say(topXstring)
market_cap_short = int(int(round(market_cap_usd,-9))/int(1000000000)) except:
rounded_mcap = str(market_cap_short)+"B" bot.say("The use is 'top' and then a digit 1 - 10")
else:
rounded_mcap = "tiny"
topXstring += "{0}. {1} ${2} | ".format(rank, symbol, rounded_mcap) #TODO: add price_usd, rounded
bot.say(topXstring)
except:
bot.say("Error parsing ticker, or maybe double check the code")
else:
bot.say("The use is 'top' and then a digit 1 - 10")
@sopel.module.commands('okc', 'okcoin') @sopel.module.commands('okc', 'okcoin')
def okc(bot, trigger): def okc(bot, trigger):