Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
crypto-chat/logic/currency.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
41 lines (35 sloc)
1.44 KB
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
import requests | |
import json | |
class Currency: | |
def __init__(self): | |
self.currencyName = None | |
self.url = "https://coinranking1.p.rapidapi.com/reference-currencies" | |
self.headers = { | |
"X-RapidAPI-Key": "eeb1cf1684msh83985ef0f081d92p1754ddjsn6941f32fe3d1", | |
"X-RapidAPI-Host": "coinranking1.p.rapidapi.com" | |
} | |
self.querystring = {"limit": "10", "offset": "0"} | |
def apiAllCurrency(self): | |
# we're getting all the coins | |
val = requests.get(self.url, headers=self.headers, params=self.querystring) | |
data = json.loads(val.text) | |
return data | |
def getAllCurrency(self): | |
data = self.apiAllCurrency() | |
print("\n data", data) | |
print("Total Currencies: ", data["data"]["stats"]["total"]) | |
for coin in data["data"]["currencies"]: | |
print("-----------------------------------------------------------------------------------------\n") | |
print("\033[1;3mUUID:\033[0m ", coin["uuid"]) | |
print("\033[1;3mtype:\033[0m ", coin["type"]) | |
print("\033[1;3mSymbol:\033[0m ", coin["symbol"]) | |
print("\033[1;3mName:\033[0m ", coin["name"]) | |
print("\033[1;3mSign:\033[0m ", coin["sign"]) | |
print("\033[1;3mImage Link:\033[0m ", coin["iconUrl"]) | |
def setCurrency(self, currencyName): | |
data = self.apiAllCoin() | |
print("set all currency all currency") | |
# coinId | |
for currency in data["data"]["coins"]: | |
if currency["symbol"].lower() == currencyName: | |
self.currencyName = currency["uuid"] |