-
-
Save iannase/38ac668c43958c4ff5de72543139cdb7 to your computer and use it in GitHub Desktop.
| import requests | |
| import json | |
| while True: | |
| # base URLs | |
| globalURL = "https://api.coinmarketcap.com/v1/global/" | |
| tickerURL = "https://api.coinmarketcap.com/v1/ticker/" | |
| # get data from globalURL | |
| request = requests.get(globalURL) | |
| data = request.json() | |
| globalMarketCap = data['total_market_cap_usd'] | |
| # menu | |
| print() | |
| print("Welcome to the CoinMarketCap Explorer!") | |
| print("Global cap of all cryptocurrencies: $" + str(globalMarketCap)) | |
| print("Enter 'all' or 'name of crypto' (i.e. bitcoin) to see the name of the top 100 currencies or a specific currency") | |
| print() | |
| choice = input("Your choice: ") | |
| if choice == "all": | |
| request = requests.get(tickerURL) | |
| data = request.json() | |
| for x in data: | |
| ticker = x['symbol'] | |
| price = x['price_usd'] | |
| print(ticker + ":\t\t$" + price) | |
| print() | |
| else: | |
| tickerURL += '/'+choice+'/' | |
| request = requests.get(tickerURL) | |
| data = request.json() | |
| ticker = data[0]['symbol'] | |
| price = data[0]['price_usd'] | |
| print(ticker + ":\t\t$" + price) | |
| print() | |
| choice2 = input("Again? (y/n): ") | |
| if choice2 == "y": | |
| continue | |
| if choice2 == "n": | |
| break |
Nice work
is price for sell or for buy
hi i need assistance
i keep on getting this error in the shell
Traceback (most recent call last):
File "C:\Users\admin\AppData\Local\Programs\Python\Python312\Lib\site-packages\requests\models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\admin\AppData\Local\Programs\Python\Python312\Lib\json_init_.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\admin\AppData\Local\Programs\Python\Python312\Lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\admin\AppData\Local\Programs\Python\Python312\Lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\admin\desktop\capstone_project\setup.py", line 11, in
data = request.json()
^^^^^^^^^^^^^^
File "C:\Users\admin\AppData\Local\Programs\Python\Python312\Lib\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
how can put someone this api script in a html file ?