Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Set up helper functions for getting all coins a currency and setting …
…a defaul currency with getting a single detail on a coin.
- Loading branch information
Showing
16 changed files
with
263 additions
and
21 deletions.
There are no files selected for viewing
BIN
-460 Bytes
data/__pycache__/user.cpython-310.pyc
Binary file not shown.
This file was deleted.
Oops, something went wrong.
BIN
+749 Bytes
database/__pycache__/mongo.cpython-310.pyc
Binary file not shown.
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,11 @@ | ||
import pymongo | ||
|
||
|
||
class Mongo: | ||
def __init__(self): | ||
url = "mongodb+srv://:@churchee.qbavh.gcp.mongodb.net/?retryWrites=true&w=majority" | ||
self.client = pymongo.MongoClient(url) | ||
|
||
def getClient(self): | ||
print("client", self.client) | ||
return self.client['chatbox'] |
BIN
+2.89 KB
logic/__pycache__/coin.cpython-310.pyc
Binary file not shown.
BIN
+1.79 KB
logic/__pycache__/currency.cpython-310.pyc
Binary file not shown.
BIN
+2.21 KB
logic/__pycache__/help.cpython-310.pyc
Binary file not shown.
BIN
+334 Bytes
(120%)
logic/__pycache__/welcome.cpython-310.pyc
Binary file not shown.
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,77 @@ | ||
import requests | ||
import json | ||
|
||
class Coin: | ||
def __init__(self): | ||
self.coinId = None | ||
self.headers = { | ||
"X-RapidAPI-Key": "eeb1cf1684msh83985ef0f081d92p1754ddjsn6941f32fe3d1", | ||
"X-RapidAPI-Host": "coinranking1.p.rapidapi.com" | ||
} | ||
|
||
def apiAllCoin(self): | ||
# we're getting all the coins | ||
url = 'https://coinranking1.p.rapidapi.com/coins' | ||
querystring = {"referenceCurrencyUuid": "yhjMzLPhuIDl", "timePeriod": "24h", | ||
"tiers[0]": "1", "orderBy": "marketCap", "orderDirection": "desc", "limit": "50", "offset": "0"} | ||
val = requests.get(url, headers=self.headers, params=querystring) | ||
data = json.loads(val.text) | ||
return data | ||
|
||
def apiCoin(self): | ||
# we're getting all the coins | ||
url = 'https://coinranking1.p.rapidapi.com/coin/' + self.coinId | ||
querystring = { | ||
"referenceCurrencyUuid": "yhjMzLPhuIDl", "timePeriod": "24h"} | ||
val = requests.get(url, headers=self.headers, params=querystring) | ||
data = json.loads(val.text) | ||
return data | ||
|
||
def getAllCoin(self): | ||
data = self.apiAllCoin() | ||
# print(val.text) | ||
print("\n") | ||
print("Total Coins: ", data["data"]["stats"]["totalCoins"]) | ||
for coin in data["data"]["coins"]: | ||
print("-----------------------------------------------------------------------------------------\n") | ||
print("\033[1;3mRanking:\033[0m ", coin["rank"]) | ||
print("\033[1;3mSymbol:\033[0m ", coin["symbol"]) | ||
print("\033[1;3mCoin name:\033[0m ", coin["name"]) | ||
print("\033[1;3mBTC Price:\033[0m ", coin["btcPrice"]) | ||
print("\033[1;3mMarket Cap:\033[0m ", coin["marketCap"]) | ||
print("\033[1;3mPrice:\033[0m ", coin["price"]) | ||
print("\033[1;3mImage Link:\033[0m ", coin["iconUrl"]) | ||
|
||
return True | ||
|
||
def getCoin(self, coinName): | ||
data = self.apiAllCoin() | ||
|
||
for x in data["data"]["coins"]: | ||
if x["symbol"].lower() == coinName: | ||
self.coinId = x["uuid"] | ||
|
||
val = self.apiCoin() | ||
coin = val["data"]["coin"] | ||
print("-----------------------------------------------------------------------------------------\n") | ||
print("\033[1;3mUUID:\033[0m ", coin["uuid"]) | ||
print("\033[1;3mRanking:\033[0m ", coin["rank"]) | ||
print("\033[1;3mSymbol:\033[0m ", coin["symbol"]) | ||
print("\033[1;3mCoin name:\033[0m ", coin["name"]) | ||
print("\033[1;3mBTC Price:\033[0m ", coin["btcPrice"]) | ||
print("\033[1;3mMarket Cap:\033[0m ", coin["marketCap"]) | ||
print("\033[1;3mPrice:\033[0m ", coin["price"]) | ||
print("\033[1;3mImage Link:\033[0m ", coin["iconUrl"]) | ||
print("\033[1;3mNumber Of Exchanges:\033[0m ", coin["numberOfExchanges"]) | ||
print("\033[1;3mWebsite:\033[0m ", coin["websiteUrl"]) | ||
print("\033[1;3mNumber Of Markets:\033[0m ", coin["numberOfMarkets"]) | ||
print("\033[1;3mPrice At:\033[0m ", coin["priceAt"]) | ||
print("\033[1;3m24hVolume:\033[0m ", coin["24hVolume"]) | ||
print("\033[1;3mFully Diluted Market Cap:\033[0m ", coin["fullyDilutedMarketCap"]) | ||
print("\033[1;3mCoin Ranking Url:\033[0m ", coin["coinrankingUrl"]) | ||
print("\033[1;3mChange:\033[0m ", coin["change"]) | ||
|
||
return True | ||
|
||
|
||
|
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,41 @@ | ||
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"] |
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,73 @@ | ||
from logic.coin import Coin | ||
from logic.currency import Currency | ||
import time | ||
|
||
|
||
class Help: | ||
|
||
funcList = [ | ||
{"action": "get all currency", "details": "This gives you details about all the currency we support"}, { | ||
"action": "set currency [currency symbol]", "details": "You can use this command to set a default currency to your account profile eg 'set currency usd'"}, | ||
{"action": "get all coin", | ||
"details": "You can get all the coins we currently support"}, | ||
{"action": "get coin [coin symbol]", | ||
"details": "This gives you information about the specific coin eg 'get coin bitcoin'"} | ||
] | ||
|
||
def howItWorks(self): | ||
print( | ||
"\n \033[1;3mPlease read the following steps to guide you on how this platform works \033[0m") | ||
# time.sleep(2) | ||
print( | ||
"\033[1;3mWe've created a shortcut list of commands you can input to get up to speed fast \033[0m\n") | ||
# time.sleep(2) | ||
print( | ||
"\033[1;3mPlease enter the following command below to get started. Goodluck...\033[0m \n") | ||
for x in self.funcList: | ||
print("* \033[1;3m" + x["action"] + "\033[0m") | ||
print(x["details"]) | ||
print("\n") | ||
|
||
def callFunc(self): | ||
|
||
print("\n") | ||
time.sleep(1) | ||
|
||
# get an action from the user | ||
action = input("Please enter your command to get started: ") | ||
|
||
# split the command and convert it to lower case | ||
cmd = action.lower().split() | ||
|
||
# if we want the program to continue | ||
cund = False | ||
|
||
# So we're | ||
newCoin = Coin() | ||
newCurrency = Currency() | ||
if cmd[0] == "get": | ||
if cmd[1] == "all": | ||
if cmd[2] == "coin": | ||
cund = newCoin.getAllCoin() | ||
elif cmd[2] == "currency": | ||
cund = newCurrency.getAllCurrency() | ||
else: | ||
print( | ||
"The command you provided isn't recornized. Review \033[1;3m how it works \033[0m for better understanding.") | ||
print("Enter \033[1;3mExit\033[0m to quit the program") | ||
self.callFunc() | ||
if cmd[1] == "coin": | ||
cund = newCoin.getCoin(cmd[2]) | ||
elif (["set", "currency"] and cmd) == cmd and len(cmd) == 3: | ||
cund = newCurrency.setCurrency(cmd[2]) | ||
elif cmd[0] == "exit": | ||
exit() | ||
else: | ||
print( | ||
"The command you provided isn't recornized. Review \033[1;3m how it works \033[0m for better understanding.") | ||
print("Enter \033[1;3mExit\033[0m to quit the program") | ||
self.howItWorks() | ||
self.callFunc() | ||
|
||
if cund: | ||
self.callFunc() |
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
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 |
---|---|---|
@@ -1,9 +1,28 @@ | ||
from logic.welcome import Welcome | ||
from logic.help import Help | ||
from database.mongo import Mongo | ||
import time | ||
|
||
def main(): | ||
newWelcome = Welcome() | ||
# Welcome the user and get their private information | ||
newWelcome.welcomeUser() | ||
|
||
proceed = False | ||
newWelcome = Welcome() | ||
# Welcome the user and get their private information | ||
proceed = newWelcome.welcomeUser() | ||
|
||
# check if we've completed the task for | ||
# welcoming the user then proceed to the next task | ||
if not proceed: | ||
print("We're sorry but we're going to have to terminate this process becuase we couldn't onboard you. \n") | ||
print("Please try again. \n") | ||
time.sleep(2) | ||
exit() | ||
|
||
newHelp = Help() | ||
newHelp.howItWorks() | ||
newHelp.callFunc() | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
main() |
BIN
+455 Bytes
model/__pycache__/user.cpython-310.pyc
Binary file not shown.
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,5 @@ | ||
class User: | ||
def __init__(self, name, email): | ||
self.name = name | ||
self.email = email | ||
|
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,2 @@ | ||
pymongo>=4.3.3 | ||
requests>=2.28.1 |