TaylorFacen / nomics-python

A Python wrapper for the Nomics API
MIT License
52 stars 14 forks source link

Wrapper doesn't work on one OS, but works fine on another. #34

Closed JoshPaulie closed 3 years ago

JoshPaulie commented 4 years ago

Function from my discord bot

Hey there! So I got my script to work on my iPad, but when I tried to implement the functions into my discord bot, I don't get any data returned. The following code is run from my discord bot on a windows machine.

from nomics import Nomics

def get_coin_info(coin_symb: str):
    nomics = Nomics(<key, properly imported>)
    coin_data = nomics.Currencies.get_currencies(ids=coin_symb)
    price = round(float(coin_data[0]['price']), 2)
    pprice = f"${price:,}"
    coin_name = coin_data[0]['name']
    coin_symbol = coin_data[0]['symbol']
    return f"{coin_name} ({coin_symbol})", pprice

which returns discord.ext.commands.errors.CommandInvokeError: Command raised an exception: IndexError: list index out of range

because the coin_data list is returned []

The code that works well, from my iPad

from nomics import Nomics
import pprint
nomics = Nomics(<key>)

coin_symbs = ["BTC", "LINK", "ETC", "XRP", "LTC", "USDT", "BCH"]

for coin in coin_symbs:
    coin_data = nomics.Currencies.get_currencies(ids = coin)
    price = round(float(coin_data[0]['price']), 2)
    str_price = f"${price:,}"
    print(f"{coin_data[0]['name']} ({coin_data[0]['symbol']}) - {str_price}")

Any ideas? Please let me know how I can give you more detail if needed.

Project libraries

----------------- ---------
aiohttp           3.6.3
async-timeout     3.0.1
attrs             19.3.0
certifi           2020.6.20
chardet           3.0.4
colored           1.4.2
discord           1.0.1
discord.py        1.5.1
dnspython         2.0.0
googletrans       3.0.0
h11               0.9.0
h2                3.2.0
hpack             3.0.0
hstspreload       2020.10.6
httpcore          0.9.1
httpx             0.13.3
hyperframe        5.2.0
idna              2.10
motor             2.3.0
multidict         4.7.6
nomics-python     3.1.0
numpy             1.19.0
pandas            1.0.5
pip               19.0.3
progress          1.5
pymongo           3.11.0
python-dateutil   2.8.1
pytz              2020.1
requests          2.24.0
rfc3986           1.4.0
riotwatcher       3.1.1
setuptools        40.8.0
six               1.15.0
sniffio           1.2.0
typing-extensions 3.7.4.3
urllib3           1.25.10
websockets        8.1
yarl              1.4.2
TaylorFacen commented 3 years ago

@JoshPaulie Looks like the code that you're running on the discord bot is pulling data for multiple coins at once and the code on your iPad is looping through a list of coins. Can you try running the exact same code on your iPad to see if it works there?

JoshPaulie commented 3 years ago

@TaylorFacen You were exactly right. Sorry for the bother, thanks for the help. Good wrapper