Skip to content
Permalink
Browse files
Fixed onboarding and set currency
  • Loading branch information
oshianor committed Nov 23, 2022
1 parent 5c5cd94 commit fa9f2e6fe2f33afcced7dc4406d44e3831e6f240
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 26 deletions.
@@ -1 +1,3 @@
__pycache__
__pycache__/
*.py[cod]
*$py.class
Binary file not shown.
@@ -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']
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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()
@@ -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
@@ -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,18 +19,18 @@ 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:
print("* \033[1;3m" + x["action"] + "\033[0m")
print(x["details"])
print("\n")

def callFunc(self):
def callFunc(self, user):

print("\n")
time.sleep(1)
@@ -58,16 +60,18 @@ 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:
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()
self.callFunc(user)

if cund:
self.callFunc()
self.callFunc(user)
@@ -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"))
@@ -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)



0 comments on commit fa9f2e6

Please sign in to comment.