def add_frnd(id): # function for adding a friend. frnd = spy("", "", 0, 0.0) # saving the input in the friend list frnd.name = raw_input("Enter your friends name: ") frnd.sal = raw_input("Salutation : ") frnd.age = input("Enter your friend age: ") frnd.rating = input("Enter your friend rating: ") frnd.is_online = True if len(frnd.name) > 2 and frnd.age > 14: # validating name and age #frnd_list.append(frnd) with open("friends.csv", "a") as friends_data: writer = csv.writer(friends_data) writer.writerow([ frnd.name, frnd.sal, frnd.rating, frnd.age, frnd.is_online, id ]) frnd_list.append(frnd) print "You have successfully added a friend." else: print "The friend cannot be added " return len(frnd_list) # return the total number of frind in the list.
def login(name, password): # parameters taken are spy name and password c = 0 try: # reading data from csv to check if user name and password is correct with open("spy_list.csv", "rb") as spy_data: read = csv.reader(spy_data) for row in read: if row[0] == name and pbkdf2_sha256.verify( password, row[4]): # verification of password c += 1 print 'Login Successful' engine.say('Login Successful') engine.runAndWait() # defining parameters for calling spy chat name = row[0] age = row[1] rating = row[2] spy_login = spy(name, age, rating) # defining class object start_chat(spy_login.name, spy_login.age, spy_login.rating) # calling spy_chat break if c == 0: print 'invalid name or password' except Exception as e: print e print 'Exception in login'
def load_frnds(): # this load the friend list from .csv file with open("friends.csv", "rb") as friends_data: reader = list(csv.reader(friends_data)) for row in reader[1:]: #print row frnd = spy(name=row[0], salutation=row[1], rating=row[3], age=row[2]) frnd_list.append(frnd)
def friend_list(sname): with open('friend.csv', 'rb') as friend_data: read = csv.reader(friend_data) x = 1 for row in read: if row[1] == sname: s = spy(row[0], row[2], row[3]) friends.append(s) print str(x) + '. ' + row[0] x += 1 if x == 0: print 'No Friends'
def add_friend(): #Function to add frien which is self explanatory name = raw_input("Please add your friend's name: ") salutation = raw_input("Are they Mr. or Ms.?: ") age = int(raw_input("Age?")) rating = float(raw_input("Spy rating?")) if (len(name)) > 0 and age > 12 and (rating >= 0 and rating <= 5): spy_friend = spy(name, salutation, age, rating) friend_list.append(spy_friend) print 'Friend Added!' else: print 'Sorry! Invalid entry. We can\'t add spy with the details you provided'
def add_friend(sname): salutation = raw_input("Are they Mr. or Ms.?: ") name = raw_input("Please add your friend's name:") name = salutation.capitalize() + ' ' + name.capitalize() age = input("Age?") rating = input("Spy rating?") x = 0 # Add Friend here we don't need any constraints as they are already applied while adding a user try: with open('spy_list.csv', 'rb') as s1: read = csv.reader(s1) for r in read: if r[0] == name and r[1] == str(age): x += 1 new_friend = spy(name, age, rating) friends.append(new_friend) with open('friend.csv', 'ab') as friend_data: write = csv.writer(friend_data) write.writerow( [name, sname, str(age), str(rating), True]) print 'FRIEND ADDED \n Friend List' friend_list(sname) engine.say('Friend Added') engine.runAndWait() if x == 0: print 'Sorry! Invalid entry. We can\'t add spy with the details you provided' engine.say( 'Sorry! Invalid entry. We can\'t add spy with the details you provided' ) engine.runAndWait() return add_friend(sname) return len(friends) except Exception as e: print e print 'exception in add friend'
def new_user(): age = 0 rating = 0.0 is_online = False f = True engine.say('May I know your good name !') engine.runAndWait() salutation = raw_input('enter salutation: ') salutation = salutation.strip(' ') salutation = salutation.capitalize() name = raw_input('enter name: ') name = name.strip(' ') if len(name) > 0 and name.isalnum(): # constraints on name name = salutation + ' ' + name.capitalize( ) # combining name and salutation engine.say('How old are you?') engine.runAndWait() try: age = input('age: ') if (age > 12) and (age < 50): # constraints on age engine.say('Please, rate spy!') engine.runAndWait() rating = input("What is your spy rating (0 to 5)?") # complementing spy according to rating if 4.5 < rating <= 5: print 'Great ace!' engine.say('Great ace!') elif (rating > 3.5) and (rating <= 4.5): print 'You are one of the good ones.' engine.say('You are one of the good ones.') elif 2.5 <= rating <= 3.5: print 'You can always do better' engine.say('You can always do better') else: print 'We can always use somebody to help in the office.' engine.say( 'We can always use somebody to help in the office.') engine.runAndWait() spy_is_online = True engine.say('Enter password please!') engine.runAndWait() password = raw_input('enter password') # taking password confirm_password = raw_input( 'confirm password') # confirming password # constraints on password if (password == confirm_password ) and password.isalnum() and len(password) < 10: password = pbkdf2_sha256.hash( password) # encoding password else: print 'invalid password! password can only have numbers or alphabets' engine.say( 'invalid password! password can only have numbers or alphabets' ) engine.runAndWait() while f: engine.say('Email id please!') engine.runAndWait() # taken for confirming user identity if it already exists in the file try: email = raw_input("enter the email: ") with open('spy_list.csv', 'rb') as fd: # opening csv file in read mode read = csv.reader(fd) for row in read: if email == row[5]: # comparing email print 'Email Id already exist!!! Try new one' else: f = False except Exception as e: print e # printing exception print 'exception in email comparison' print("Authentication is complete.\nSpy " + name + " \nSpy Age:" + str(age) + "\nSpy Rating:" + str(rating) + " \n We are proud to have you on board!") engine.say("Authentication is complete.Spy " + name + " Spy Age:" + str(age) + " Spy Rating:" + str(rating) + " We are proud to have you on board!") engine.runAndWait() print("You can proceed.") spy_new = spy(name, age, rating) # defining class object start_chat(spy_new.name, spy_new.age, spy_new.rating) else: print("Sorry! you are not of appropriate age to be a Spy.") engine.say( "Sorry! you are not of appropriate age to be a Spy.") engine.runAndWait() except Exception as e: print e print "Invalid age entry" else: print("Sorry! Invalid name") engine.say("Sorry! Invalid name") engine.runAndWait() try: with open("spy_list.csv", "ab") as spy_data: write = csv.writer(spy_data) write.writerow( [name, str(age), str(rating), True, password, email]) except Exception as e: print e print 'exception in adding new spy'
def signup(): spy2 = spy("", "", 0, 0.0) # Asking for name of Spy spy2.name = raw_input("\nEnter your Spy Name : ") # validation For the name . SPACES and NUMBERS are not allowed. if spy2.name.isspace(): print Fore.RED + "Ooops! Enter a valid name." elif spy2.name.isdigit(): print Fore.RED + "Ooops! Enter a valid name." elif len(spy2.name) > 2: print "Welcome " + spy2.name + ", glad to have you back with us.\n" # Asking for the SALUTATION from the spy spy2.salutation = raw_input("What should we call you (Mr. or Ms.) : ") # Verifying that the Salutation is CORRECT or not. if spy2.salutation == "Mr." or spy2.salutation == "Ms." or spy2.salutation == "mr." or spy2.salutation == "ms.": password = raw_input("Choose a Password for Login : "******"You didn't created your password." print "Alright %s %s. I'd like to know a little bit more about you...\n" % ( spy2.salutation, spy2.name) # Asking the age of spy and verifying the AGE spy2.age = input("What's your age : ") if 14 < spy2.age <= 60: # Asking fro the rating of Spy print "\nRating Should be Between 0 to 10 ." spy2.rating = input("What are your Ratings : ") # Verifying Rating . if spy2.rating > 10 or spy2.rating < 0: print "Oops! Invalid Rating." else: # Display an appropriate message based on spy rating if 10 >= spy2.rating > 7: print "\nGreat Spy.\n" elif 7 > spy2.rating > 5: print "\nGood Spy.\n" elif 5 < spy2.rating < 3: print "\nAverage spy\n" else: print "\nWho Hired You\n" spy_is_online = True print "Authentication complete. \nWelcome %s %s , Age: %d , Rating: %.1f .\n" % ( spy2.salutation, spy2.name, spy2.age, spy2.rating) with open("signup.csv", "a") as friends_data: writer = csv.writer(friends_data) writer.writerow([ spy2.name, spy2.salutation, spy2.rating, spy2.age, spy2.is_online ]) #frnd_list.append(spy2) with open("login.csv", "a") as login_data: writer = csv.writer(login_data) writer.writerow([spy2.name, password]) #frnd_list.append(spy2) menu(spy2.name) else: print Fore.RED + "You are not eligible to be a spy." else: # printing message for invalid Salutation. print Fore.RED + "Invalid Salutation." # condition for invalid name of Spy... else: print Fore.RED + "Ooops! Enter a valid name."
from spy_details import spy1, spy, chatmessage, id from steganography.steganography import Steganography from datetime import datetime import csv from colorama import Fore # list of default Status message or the previous status status_message = [ "Busy.", "Leave a message.", "Don't Disturb.", "Help me !!! " ] # all the information of frnds stored in this list frnd1 = spy("sonu", "Mr.", 19, 8.5) frnd2 = spy("monu", "Mr.", 19, 9) frnd_list = [frnd1, frnd2] # all id password of spy is in this list. ID = [] # All chats are saved here. chats = [] # list of special messages Special_message = [ "SOS", "HELP", "SAVE", "NEED" "HELP ME", "SAVE ME", "NEED HELP", "NEED BACKUP" ] def load_frnds(): # this load the friend list from .csv file with open("friends.csv", "rb") as friends_data: reader = list(csv.reader(friends_data)) for row in reader[1:]: