diff --git a/data/__pycache__/user.cpython-310.pyc b/data/__pycache__/user.cpython-310.pyc deleted file mode 100644 index 817596f..0000000 Binary files a/data/__pycache__/user.cpython-310.pyc and /dev/null differ diff --git a/data/user.py b/data/user.py deleted file mode 100644 index dc602c2..0000000 --- a/data/user.py +++ /dev/null @@ -1,5 +0,0 @@ -class User: - def __init__(self, name, phoneNumber): - self.name = name - self.phoneNumber = phoneNumber - diff --git a/database/__pycache__/mongo.cpython-310.pyc b/database/__pycache__/mongo.cpython-310.pyc new file mode 100644 index 0000000..2f808ef Binary files /dev/null and b/database/__pycache__/mongo.cpython-310.pyc differ diff --git a/database/mongo.py b/database/mongo.py new file mode 100644 index 0000000..87b7bb9 --- /dev/null +++ b/database/mongo.py @@ -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'] diff --git a/logic/__pycache__/coin.cpython-310.pyc b/logic/__pycache__/coin.cpython-310.pyc new file mode 100644 index 0000000..7635b36 Binary files /dev/null and b/logic/__pycache__/coin.cpython-310.pyc differ diff --git a/logic/__pycache__/currency.cpython-310.pyc b/logic/__pycache__/currency.cpython-310.pyc new file mode 100644 index 0000000..99bb91e Binary files /dev/null and b/logic/__pycache__/currency.cpython-310.pyc differ diff --git a/logic/__pycache__/help.cpython-310.pyc b/logic/__pycache__/help.cpython-310.pyc new file mode 100644 index 0000000..1ba9969 Binary files /dev/null and b/logic/__pycache__/help.cpython-310.pyc differ diff --git a/logic/__pycache__/welcome.cpython-310.pyc b/logic/__pycache__/welcome.cpython-310.pyc index 5f0f56c..91738b7 100644 Binary files a/logic/__pycache__/welcome.cpython-310.pyc and b/logic/__pycache__/welcome.cpython-310.pyc differ diff --git a/logic/coin.py b/logic/coin.py new file mode 100644 index 0000000..b9951db --- /dev/null +++ b/logic/coin.py @@ -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 + + + \ No newline at end of file diff --git a/logic/currency.py b/logic/currency.py new file mode 100644 index 0000000..3e81b2c --- /dev/null +++ b/logic/currency.py @@ -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"] diff --git a/logic/help.py b/logic/help.py new file mode 100644 index 0000000..20b2391 --- /dev/null +++ b/logic/help.py @@ -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() diff --git a/logic/welcome.py b/logic/welcome.py index 0f4f65a..42637da 100644 --- a/logic/welcome.py +++ b/logic/welcome.py @@ -1,20 +1,39 @@ -from data.user import User +from model.user import User +from database.mongo import Mongo class Welcome: def welcomeUser(self): + client = Mongo() + db = client.getClient() + print("Welcome to crypto chat-box.\n") print("Where we make it easier for you to access realtime prices from your favourite coin") print("To enable your experience smooth, We've created a helper function to help do this faster with a shortcut.\n") - # get the user name - name = self.provideName() + # get the email address + email = self.provideEmail() + # newUser = User(name, email) + userModel = db["account"] + + # first we need to find the account if it present + # we'll use their email address + userExist = userModel.find_one({"email": email}) - print("\nThank you for providing your name. We just need one last thing from you.") + # print(userExist) + # check if a user was found + if userExist: + print("Welcome " + userExist["name"].capitalize() + + " back to crypto chat-box.\n") + else: + print("\nThank you for providing your Email. We just need one last thing from you.") + # get the user name + name = self.provideName() + print("Thank you for completing your onboarding.. " + name.capitalize()) + userModel.insert_one({"email": email, "name": name, + "currencyName": "USD", "currencyID": "yhjMzLPhuIDl"}) - # get the mobile number - phoneNumber = self.providePhoneNumber() - newUser = User(name, phoneNumber) + return True def provideName(self): name = str(input("how can we address you. Please provide your name: \n")) @@ -23,9 +42,9 @@ class Welcome: self.provideName() return name - def providePhoneNumber(self): - phoneNumber = str(input("Please provide your mobile number: \n")) - if phoneNumber == "": - print("To proceed, you must provide your mobile number.") - self.providePhoneNumber() - return phoneNumber + def provideEmail(self): + email = str(input("Please provide your email address: \n")) + if email == "": + print("To proceed, you must provide your email address.") + self.provideemail() + return email diff --git a/main.py b/main.py index bf6a9f5..6263086 100644 --- a/main.py +++ b/main.py @@ -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() \ No newline at end of file diff --git a/model/__pycache__/user.cpython-310.pyc b/model/__pycache__/user.cpython-310.pyc new file mode 100644 index 0000000..00bbfe0 Binary files /dev/null and b/model/__pycache__/user.cpython-310.pyc differ diff --git a/model/user.py b/model/user.py new file mode 100644 index 0000000..0b53751 --- /dev/null +++ b/model/user.py @@ -0,0 +1,5 @@ +class User: + def __init__(self, name, email): + self.name = name + self.email = email + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..13513f0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pymongo>=4.3.3 +requests>=2.28.1 \ No newline at end of file