Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
from confirmDB import connection
from send_email import email
"""checks if there is any registered user with that nickname"""
def checkUnique(nick):
try:
exist = False
connect = connection() # gets the details to the database
cursor = connect.cursor() # establish a cursor to fetch the results wanted from the databse
nick = nick.lower()
sql = 'SELECT NICKNAME FROM users WHERE NICKNAME = "' + nick + '"' #sql gets the order to select all nicknames from the table users with the nickname == nick
cursor.execute(sql) # order to select executed
myresult = cursor.fetchall() # gets all the rows of nicknames where the nickname == nick
for x in myresult:
if nick in x: #check if there is already a nickname == nick
exist = True
break
if exist:
check = input("I already know one " + nick + ", is that you? ")
check = check.lower()
if check in ["yes", "y", "of course", "yap", "obviously", "indeed", "that is correct", "affirmative"]:
LOGIN(nick)
return True
else:
return False
else:
return False
except:
print("Sorry, seems that you are not connected to my databse.")
return "off"
""" process to login the user"""
def LOGIN(nick):
try:
password = input("Password: ")
ckpassword = userDetails(nick, "PASSWORD")
if password == ckpassword:
print("Logged in Successfully!")
else:
print("Failed to Login!")
LOGIN(nick)
except:
print("Sorry, seems that you are not connected to my databse.")
"""gets all the info wanted in the table users"""
def userDetails(nick, info):
try:
connect = connection()
cursor = connect.cursor()
sql = 'SELECT ' + info + ' FROM users WHERE NICKNAME = "' + nick + '"' #sql selects the info wanted about the user with nickname==nick from the table user
cursor.execute(sql) # order to select executed
myresult = cursor.fetchall() # gets all the rows of nicknames where the nickname == nick
l = str(myresult[0]) # l = ('nickname',)
final = (l[2:])
final = final[:-3]
return final
except:
pass
""" Adds new friends, collectiong and storing the information needed """
def newFriend():
try:
firstName = input("What is your first name? ")
lastName = input("What is your last name? ")
nickname = input("How should I treat you? ")
nickname = nickname.lower()
connect = connection()
cursor = connect.cursor()
sql = 'SELECT NICKNAME FROM users WHERE NICKNAME = "' + nickname + '"' #sql gets the order to select all nicknames from the table users with the nickname == nick
cursor.execute(sql) # order to select executed
myresult = cursor.fetchall() # gets all the rows of nicknames where the nickname == nick
for x in myresult:
if nickname in x:
print("I already call that to a friend. Please start again with a diferent nickname.")
return False
age = input("How old are you? ")
city = input("Where do you live? ")
mail = input("What is your email? ")
password = input("Define your password: ")
sql = "INSERT INTO users (FIRST_NAME, LAST_NAME, AGE, CITY, PASSWORD, NICKNAME, EMAIL) VALUES (%s, %s, %s, %s, " \
"%s, %s, %s) " #sql gets the order to insert all these values into the table users
val = (firstName, lastName, age, city, password, nickname, mail)
cursor.execute(sql, val) #order executed
connect.commit() # tell the database to save all the changes
sql = "INSERT INTO favourite (NICKNAME) VALUE (%s) " #sql gets the order to add the user nickname into the table favourite
val = (nickname)
cursor.execute(sql, val) #order executed
connect.commit() # tell the database to save all the changes
print(cursor.rowcount, " more friend! That's great!\n\n")
email(nickname, password, mail) #Works depending on the wifi connection / does not work with public wifi connections
return nickname
except:
print("Something went wrong")