From 9cf1a8a682e016dfe22ec64e8bbb6a76f1f1e61a Mon Sep 17 00:00:00 2001 From: Denis Emrulov Date: Thu, 29 Nov 2018 17:10:11 +0000 Subject: [PATCH] API file --- cryptocurrencyAPI.py | 64 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 cryptocurrencyAPI.py diff --git a/cryptocurrencyAPI.py b/cryptocurrencyAPI.py new file mode 100644 index 0000000..047e18f --- /dev/null +++ b/cryptocurrencyAPI.py @@ -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")