diff --git a/.gitignore b/.gitignore index ed8ebf5..0e4f7f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -__pycache__ \ No newline at end of file +__pycache__/ +*.py[cod] +*$py.class \ No newline at end of file diff --git a/database/__pycache__/mongo.cpython-310.pyc b/database/__pycache__/mongo.cpython-310.pyc index 2f808ef..79e20e0 100644 Binary files a/database/__pycache__/mongo.cpython-310.pyc and b/database/__pycache__/mongo.cpython-310.pyc differ diff --git a/database/mongo.py b/database/mongo.py index 87b7bb9..e49b94c 100644 --- a/database/mongo.py +++ b/database/mongo.py @@ -3,9 +3,9 @@ import pymongo class Mongo: def __init__(self): - url = "mongodb+srv://:@churchee.qbavh.gcp.mongodb.net/?retryWrites=true&w=majority" + url = "mongodb+srv://chatbox:chatbox@churchee.qbavh.gcp.mongodb.net/?retryWrites=true&w=majority" self.client = pymongo.MongoClient(url) def getClient(self): - print("client", self.client) + # print("client", self.client) return self.client['chatbox'] diff --git a/logic/__pycache__/coin.cpython-310.pyc b/logic/__pycache__/coin.cpython-310.pyc index 7635b36..a7d2256 100644 Binary files a/logic/__pycache__/coin.cpython-310.pyc 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 index 99bb91e..a38b1cc 100644 Binary files a/logic/__pycache__/currency.cpython-310.pyc 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 index 1ba9969..a84b1f7 100644 Binary files a/logic/__pycache__/help.cpython-310.pyc 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 91738b7..f5eeae2 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 index b9951db..3d444da 100644 --- a/logic/coin.py +++ b/logic/coin.py @@ -48,7 +48,7 @@ class Coin: data = self.apiAllCoin() for x in data["data"]["coins"]: - if x["symbol"].lower() == coinName: + if x["symbol"].lower() == coinName.lower(): self.coinId = x["uuid"] val = self.apiCoin() diff --git a/logic/currency.py b/logic/currency.py index 3e81b2c..4f4fd52 100644 --- a/logic/currency.py +++ b/logic/currency.py @@ -1,16 +1,17 @@ import requests import json - +from database.mongo import Mongo class Currency: def __init__(self): self.currencyName = None + self.currencyID = 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"} + self.querystring = {"limit": "30", "offset": "0"} def apiAllCurrency(self): # we're getting all the coins @@ -31,11 +32,38 @@ class Currency: print("\033[1;3mSign:\033[0m ", coin["sign"]) print("\033[1;3mImage Link:\033[0m ", coin["iconUrl"]) - def setCurrency(self, currencyName): - data = self.apiAllCoin() + return True + + + def setCurrency(self, user, currencyName): + client = Mongo() + db = client.getClient() + userModel = db["account"] + + data = self.apiAllCurrency() + for currency in data["data"]["currencies"]: + if currency["symbol"].lower() == currencyName.lower(): + self.currencyID = currency["uuid"] + self.currencyName = currency["symbol"] + + if not self.currencyName and self.currencyID: + print("\nWe couldn't find any currency with the name you provided. Please try again.") + + userModel.find_one_and_update({"email": user["email"]}, {'$set': {"currencyName": self.currencyName, "currencyID": self.currencyID}}) + + return True + + + def getCurrency(self, user): + client = Mongo() + db = client.getClient() + userModel = db["account"] + + userExist = userModel.find_one({"email": user["email"]}) - print("set all currency all currency") - # coinId - for currency in data["data"]["coins"]: - if currency["symbol"].lower() == currencyName: - self.currencyName = currency["uuid"] + print("\033[1;3mName:\033[0m ", userExist["name"]) + print("\033[1;3mEmail:\033[0m ", userExist["email"]) + print("\033[1;3mCurrency:\033[0m ", userExist["currencyName"]) + print("\033[1;3mCurrency UUID:\033[0m ", userExist["currencyID"]) + + return True diff --git a/logic/help.py b/logic/help.py index 20b2391..ffae874 100644 --- a/logic/help.py +++ b/logic/help.py @@ -8,6 +8,8 @@ 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 currency", + "details": "This returns your default currency set"}, {"action": "get all coin", "details": "You can get all the coins we currently support"}, {"action": "get coin [coin symbol]", @@ -17,10 +19,10 @@ class Help: 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) + 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) + time.sleep(2) print( "\033[1;3mPlease enter the following command below to get started. Goodluck...\033[0m \n") for x in self.funcList: @@ -28,7 +30,7 @@ class Help: print(x["details"]) print("\n") - def callFunc(self): + def callFunc(self, user): print("\n") time.sleep(1) @@ -58,8 +60,10 @@ class Help: self.callFunc() if cmd[1] == "coin": cund = newCoin.getCoin(cmd[2]) + if cmd[1] == "currency": + cund = newCurrency.getCurrency(user) elif (["set", "currency"] and cmd) == cmd and len(cmd) == 3: - cund = newCurrency.setCurrency(cmd[2]) + cund = newCurrency.setCurrency(user, cmd[2]) elif cmd[0] == "exit": exit() else: @@ -67,7 +71,7 @@ class Help: "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() + self.callFunc(user) if cund: - self.callFunc() + self.callFunc(user) diff --git a/logic/welcome.py b/logic/welcome.py index 42637da..a358828 100644 --- a/logic/welcome.py +++ b/logic/welcome.py @@ -13,7 +13,6 @@ class Welcome: # get the email address email = self.provideEmail() - # newUser = User(name, email) userModel = db["account"] # first we need to find the account if it present @@ -23,17 +22,22 @@ class Welcome: # print(userExist) # check if a user was found if userExist: - print("Welcome " + userExist["name"].capitalize() + - " back to crypto chat-box.\n") + print("Welcome back \033[1;3m" + userExist["name"].capitalize() + + "\033[0m, 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()) + + # create a new user record userModel.insert_one({"email": email, "name": name, - "currencyName": "USD", "currencyID": "yhjMzLPhuIDl"}) + "currencyName": "USD", "currencyID": "yhjMzLPhuIDl"}) - return True + userExist = {"email": email, "name": name, + "currencyName": "USD", "currencyID": "yhjMzLPhuIDl"} + return userExist def provideName(self): name = str(input("how can we address you. Please provide your name: \n")) diff --git a/main.py b/main.py index 6263086..fd621f8 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,6 @@ import time def main(): - proceed = False newWelcome = Welcome() # Welcome the user and get their private information proceed = newWelcome.welcomeUser() @@ -20,7 +19,7 @@ def main(): newHelp = Help() newHelp.howItWorks() - newHelp.callFunc() + newHelp.callFunc(proceed)