Skip to content
Permalink
Browse files
API file
  • Loading branch information
emrulovd committed Nov 29, 2018
1 parent 95c8644 commit 9cf1a8a682e016dfe22ec64e8bbb6a76f1f1e61a
Showing 1 changed file with 64 additions and 0 deletions.
@@ -0,0 +1,64 @@
import requests
import json
from discord.ext import commands
# I have to convert the file to discord one!

"""I took the idea from https://youtu.be/uBfZal3Ve84 but I had to add and change some parts from the code ."""
class CoinMarket:
def __init__(self, client):
client.self = client



# base URLs
@commands.command(alisases = ['coin', 'coinmarket', 'coinM'])
async def coin(self,ctx):

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 conin market cap ")
print("globall ....." + str(globalMarketCap))
print("Enter 'all' or 'name of crypto'")
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":
pass
if choice2 == "n":
pass


def setup(client):
client.add_cog(CoinMarket(client))
print("API is loaded")

0 comments on commit 9cf1a8a

Please sign in to comment.