Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |