Ejemplo n.º 1
0
def add_friend():
    #Function defined to add spy's friends alongwith the details of them
    new_friend = Spy('', '', 0, 0.0)

    new_friend.name = raw_input("Enter your friend's name Spy: ")
    if set('[~!@#$%^&*()_+{}":;\']+$ " "').intersection(new_friend.name):
        print "Invalid entry. Please Enter a valid name of single word without special characters"
        new_friend.name = raw_input("Enter your friend's name Spy: ")
    else:
        print "Thats a valid friend name"

    new_friend.salutation = raw_input("MR or MS : ")

    new_friend.name = new_friend.salutation + " " + new_friend.name

    new_friend.age = raw_input("How old is your mate?")
    new_friend.age = int(new_friend.age)

    new_friend.rating = raw_input("How amazing are they?")
    new_friend.rating = float(new_friend.rating)

    if len(new_friend.name
           ) > 0 and new_friend.age > 12 and new_friend.rating >= 3.5:

        friends.append(new_friend)
        print 'You have a new Friend <3!'
    else:
        print 'Sorry! This friend isn\'t worth you. We can\'t add spy with the details you gave'

    return len(friends)
Ejemplo n.º 2
0
def add_friend():

    new_friend = Spy('','',0,0.0)
    new_friend.name = raw_input("Please add your friend's name: ")

#Handling edge case scenarios.
    if set('[~!@#$%^&*()_+{}":;\']+$ " "').intersection(new_friend.name):
        print "Invalid entry. "
        new_friend.name = raw_input("Please re enter a valid name")
    else:
        print new_friend.name

    new_friend.salutation = raw_input("How would you like to address them? ")
    new_friend.name = new_friend.salutation + " " + new_friend.name
    new_friend.age = raw_input("How old is your friend?")
    new_friend.age = int(new_friend.age)
    new_friend.rating = raw_input("And their rating too please?")
    new_friend.rating = float(new_friend.rating)

#Mandatory conditions to be satisfied for adding a friend.
    if len(new_friend.name) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:
        friends.append(new_friend)
        print "Congratulations! You have a new friend."
    else:
        print "Uh huh! Your friend is not good enough. Try again with different details."

    return len(friends)
Ejemplo n.º 3
0
def addFriend():
    # new_friend['name']=raw_input("Enter your Friend's name.. ")
    # new_friend['salutation']=raw_input('are they Mr. or Ms.? ')
    # new_friend['age']=input('Age? ')
    # new_friend['rating']=input('Rating? ')

    newspy = Spy(raw_input("Please enter your friend's name:"), raw_input("Are they Mr. or Ms.?: "),
                 input("What's the age?"), input("What is their Spy rating?"))

    if newspy.salutation == 'Mr.' or newspy.salutation == 'mr.':
        newspy.salutation = 'Mr.'
    else:
        newspy.salutation = 'Ms.'

        newspy.name = newspy.salutation + newspy.name

    if len(newspy.name) > 0 and newspy.age > 12 and newspy.age < 50:
        friends.append(newspy)
        with open("friends.csv.txt", "a") as friends_data:
            writer = csv.writer(friends_data)
            writer.writerow([newspy.name, newspy.salutation, newspy.age, newspy.rating, True])
        print "Friend Added !!"
    else:
        print 'The crediantials don\'t match the profile of a spy'

    return len(friends)
Ejemplo n.º 4
0
def load_friends():
    with open("friends.csv", "r") as friends_data:
        reader = csv.reader(friends_data)
        for row in reader:
            spy_friend = Spy()
            spy_friend.set_spy_name(row[0])
            spy_friend.set_spy_salutation(row[1])
            spy_friend.set_spy_age(int(row[2]))
            spy_friend.set_spy_rating(float(row[3]))
            spy.get_spy_friends().append(spy_friend)
Ejemplo n.º 5
0
def add_friend():

    new_friend = Spy('', '', 0, 0.0)

    new_friend.name = raw_input("Please add your friend's name: ")
    if new_friend.name.isalpha(
    ) == True:  # isalpha() is function here used to check whether an entry from user is string or not.
        new_friend.salutation = raw_input("Are they Mr. or Ms.?: ")

        new_friend.name = new_friend.salutation + " " + new_friend.name

        new_friend.age = raw_input("What is their Age?")
        if new_friend.age.isdigit():
            new_friend.age = int(new_friend.age)

            new_friend.rating = raw_input("what is their Spy rating?")
            if new_friend.rating.isdigit():
                new_friend.rating = float(new_friend.rating)

                if len(
                        new_friend.name
                ) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:
                    friends.append(new_friend)
                    print 'Friend Added!'
                else:
                    print 'Sorry! Invalid entry. We can\'t add spy with the details you provided'
            else:
                print "Rating is not feasible."
        else:
            print "Age must be of integer type. "
    else:
        print "please add a valid spy name!"
    return len(friends)
Ejemplo n.º 6
0
def add_friend():
    new_friend = Spy('', '', 0, 0.0)
    #friend name,salutation age and rating is added to data
    new_friend.name = raw_input("Please add your friend's name: ")
    if set('[~!@#$%^&*()+{}":;\']" "').intersection(new_friend.name):
        print "Invalid entry. Please enter a Valid Name!"
        new_friend.name = raw_input("enter your friend's name=")
        if set('[~!@#$%^&*()+{}":;\']" "').intersection(new_friend.name):
            print "Invalid name! Please try again."
            exit()
    else:
        print "That's a valid friend name"

    new_friend.salutation = raw_input("Are they Mr. or Ms.?: ")

    new_friend.name = new_friend.salutation + " " + new_friend.name

    new_friend.age = raw_input("Age of your friend ?")
    new_friend.age = int(new_friend.age)

    new_friend.rating = raw_input("Spy rating?")
    new_friend.rating = float(new_friend.rating)

    if len(new_friend.name
           ) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:
        friends.append(new_friend)

        print "Friend Added!"
    else:
        print "Sorry!. We can't add spy with the details you provided"

    return len(friends)
Ejemplo n.º 7
0
def add_friend():
    new_friend = Spy("", "", 0, 0.0)

    new_friend.name = raw_input("Whats the name of your friend?")
    if len(new_friend.name) > 0 and new_friend.name.isspace() == False:
        new_friend.salutation = raw_input(
            "What should we call your friend: Mr. or Ms.?")
        if new_friend.salutation == "Mr." or new_friend.salutation == "Ms.":
            new_friend.name = new_friend.salutation + " " + new_friend.name
            new_friend.age = raw_input("Whats the age?")
            new_friend.age = int(new_friend.age)
            new_friend.rating = raw_input("Whats the rating?")
            new_friend.rating = float(new_friend.rating)
            if new_friend.age > 12 and new_friend.rating > 3.5:
                friends.append(new_friend)
                print "New friend added!!"
            else:
                print "Sorry! Can't add the friend with the information provided!!"

        else:
            print "Enter Mr. or Ms."

    else:
        print "Enter valid name!!"

    return len(friends)
Ejemplo n.º 8
0
def add_friend():

    #add_friend function will add a new friend to the friends list.

    new_friend = Spy('', '', 0, 0.0)

    new_friend.name = raw_input("please add your friends name: ")
    new_friend.salutation = raw_input("Are they Mr or Ms?: ")

    new_friend.name = new_friend.salutation + " " + new_friend.name

    new_friend.age = raw_input('Age?')
    new_friend.age = int(new_friend.age)

    new_friend.rating = raw_input('rating?')
    new_friend.rating = float(new_friend.rating)

    if len(new_friend.name
           ) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:
        friends.append(new_friend)
        print 'Friend Added!'
        print friends

    else:

        print 'sorry!Invalid entry.We cant add spy with the detail you provided'

    return len(friends)
Ejemplo n.º 9
0
def add_friend():

    new_friend = Spy('', '', 0, 0.0, '')

    new_friend.name = raw_input(
        "Let\'s add your friend. Enter your friends name:")
    new_friend.salutation = raw_input(
        'What would you like us to call him/her? Mr. or Ms.?:')

    new_friend.name = new_friend.salutation + " " + new_friend.name

    new_friend.age = raw_input("Enter Age")
    new_friend.age = int(new_friend.age)

    new_friend.rating = raw_input("Enter spy rating")
    new_friend.rating = float(new_friend.rating)

    if len(new_friend.name
           ) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:
        friends.append(new_friend)
        print colored('Congratulation! Your friend has been added!', 'blue',
                      'on_grey')
    else:
        print colored('OOPS! Unable to add spy with the details you provided',
                      'red', 'on_white')

    return len(friends)
Ejemplo n.º 10
0
def add_friend():
    #Initializing The Variable new_friend
    new_friend = Spy('', '', 0, 0.0)
    #Getting Name Of the Friend
    new_friend.name = raw_input("Please add your friend's name: ")
    #Getting Salutation Of the Friend
    new_friend.salutation = raw_input("Are they Mr. or Ms.?: ")
    #Concatinating Salutation And Name
    new_friend.name = new_friend.salutation + " " + new_friend.name
    #Getting Age
    new_friend.age = raw_input("Age?")
    #Converting Age To Integer
    new_friend.age = int(new_friend.age)
    #Getting Rating
    new_friend.rating = raw_input("Spy rating?")
    #Converting Rating To FloatingPoint
    new_friend.rating = float(new_friend.rating)
    #If Friend's Name is Not Empty ,Age is above 12 and friend's rating is above or equals to spy's rating
    if len(
            new_friend.name
    ) > 0 and new_friend.age > 12 and new_friend.age < 50:  #new_friend.rating >= spy.rating:
        friends.append(new_friend)  #Add Friend to The Friends List
        print 'Friend Added!'
    else:  #If The Required Conditions are not Met
        print 'Sorry! Invalid entry. We can\'t add spy with the details you provided'

    return len(friends)  #Return The Length of the friends list
def add_friend():
    #spy is a class for adding a friend
    new_friend = Spy('', '', 0, 0.0)

    #input your friends name please!!!!
    new_friend.name = raw_input(
        "Please enter your friend's name you would like to add in a spyChat: ")
    new_friend.salutation = raw_input("Are your friend Mr. or Ms.?: ")

    #printing friends name with salutation
    new_friend.name = new_friend.salutation + " " + new_friend.name

    new_friend.age = raw_input("Please enter your Age?")

    #converting string to integer as age is an integer, not a string
    new_friend.age = int(new_friend.age)

    new_friend.rating = raw_input("Please enter your Spy rating?")

    #converting string to float as rating is an float, not a string
    new_friend.rating = float(new_friend.rating)

    #based on the below conditions if it meets, then friends will be added else not added
    if len(new_friend.name
           ) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:
        friends.append(new_friend)
        print 'Congratulations!!!!! Friend Added successfully!'
    else:
        print 'Sorry for that! we can\'t add your friend due to invalid entry.'

#returning number of friends added
    return len(friends)
Ejemplo n.º 12
0
def add_friend():
    new_friend = Spy('', '', 0, 0.0)
    new_friend.name = raw_input("please add your friends name : ")
    new_friend.salutation = raw_input("are they mr or miss : ")
    new_friend.age = int(raw_input("age: "))
    new_friend.rating = float(raw_input("rating: "))
    if len(new_friend.name) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:
        friends.append(new_friend)
    else:
        print("sorry! invalid entry. we can't add a spy with the details you provided. please try again later. ")
    return len(friends)
Ejemplo n.º 13
0
def first_spy(spy):

    # user want too creat a new file.sp take a input from user
    # Input new user details
    # Start Chat Application 1
    # Start Chat Application 2
    # Start Chat Application 3
    # Start Chat Application 4
    spy = Spy('', '', 0, 0.0)

    spy_name = raw_input("enter ur name plz")
    if len(spy_name) > 0:
        print spy_name
        spy_salulation = raw_input("what sholud we call you mr or miss")
        print("welcome " + spy_salulation + spy_name +
              "we are glad too have you back......")
        spy.age = 0
        spy_is_online = False  # python is case sensitive launguage so in False f should be in capital
        spy_rating = 0.0
        spy.age = raw_input("please enter your age")
        spy.age = int(
            spy.age
        )  # here we have to do casting because raw_input always store a string value so we have to convert it ito integers
        if spy.age > 12 and spy.age < 50:
            # and  or are the logical opreator so they are written as they are.
            print("enter your further details please")
            spy_rating = raw_input("please enter whats ur rating")
            # now through spy_rating we have to comment the user.
            if spy_rating > 4.5:
                print("great ace!!!")
            elif spy_rating > 3.5 and spy_rating <= 4.5:
                print("you are agood one")
            elif spy_rating >= 2.5 and spy_rating <= 3.5:
                print("you can be a good spy")
            else:
                print("we always use some one in office")
            spy_is_online = True
            print("authenication complete")
            print("welcome" + spy_name + "your age is" + str(spy.age) +
                  "and ur spy rating is" + str(spy_rating))

        else:
            print("you are not allowed to use spy_chat")

        start_chat(spy)  # calling start_chat function

    else:
        print("enter ur name please and try again")
        first_spy(
            spy
        )  #we cAll first_spy function beacuse it not edd the application if user enter null in name than it restart again.
Ejemplo n.º 14
0
def add_friend():
    new_friend = Spy('', '', 0, 0.0)
    new_friend.name = raw_input("Please add your friend's name: \n")

    if set('[special symbols":;\']+$ " "').intersection(new_friend):
        print "Invalid entry."
    else:
        print new_friend

    new_friend.salutation = raw_input(
        "Formal Salutation: Mr. or Ms. or Mrs. \n")
    new_friend.name = new_friend.salutation + " " + new_friend.name

    new_friend.age = raw_input("Age?\n")
    new_friend.age = int(new_friend.age)

    new_friend.rating = raw_input("Spy rating?\n")
    new_friend.rating = float(new_friend.rating)

    if len(new_friend.name
           ) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:
        friends.append(new_friend)
        print 'New Friend Added!\n'
    else:
        print "Sorry! Invalid entry. We can\'t add spy with the details you provided!!\n"

    return len(friends)
Ejemplo n.º 15
0
def add_friend():
    #creating a new default friend
    new_friend = Spy("", "", 0, 0.0)
    time.sleep(0.3)
    new_friend.name = raw_input(
        "Input your friends name: ")  #asking for friend's name
    new_friend.name = check_name(
        new_friend.name)  #checking the validity of the name
    time.sleep(0.3)
    new_friend.sal = raw_input(
        "Is your friend Mr or Ms: ")  #asking foor salutation
    new_friend.sal = check_Sal(
        new_friend.sal)  #checking the validity of the salutation
    time.sleep(0.3)
    new_friend.age = int(
        raw_input("Age of your spy friend: "))  #age input in int
    time.sleep(0.3)
    new_friend.rating = input(
        "Enter your spy friend's spy rating: ")  #rating input in float
    if (check_age(new_friend.age)):  #check for appropriate age
        friends.append(
            new_friend
        )  #if valid new friend to be appended at the end of the friends list
        #writing details of new friend at the end of the file using ab
        with open("friends.csv", "ab") as friends_data:
            writer = csv.writer(friends_data)
            writer.writerow([
                new_friend.name, new_friend.sal, new_friend.age,
                new_friend.rating, new_friend.is0nline
            ])
    else:
        time.sleep(0.3)
        print "Sorry you are not of appropriate age to be a Spy!"  #inappropriate age

    return len(friends)  #return length of friends list
Ejemplo n.º 16
0
def add_friend():
    new_friend = Spy('', '', 0, 0.0)

    # Raw input allows to take input from user and new_friend.name is a variable where variable is stored.
    new_friend.name = raw_input("Please add your friend's name: ")
    new_friend.salutation = raw_input("Are they Mr. or Ms.?: ")

    # Variable has been updated
    new_friend.name = new_friend.salutation + " " + new_friend.name

    new_friend.age = raw_input("Age?")
    new_friend.age = int(new_friend.age)

    new_friend.rating = raw_input("Spy rating?")
    new_friend.rating = float(new_friend.rating)

    # spy friend should meet the requirements for which we apply condition using IF keyword
    if len(new_friend.name
           ) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:

        # .append adds friend to new_friend
        friends.append(new_friend)
        print 'Friend Added!'
    else:
        # \ is used before 't which is used for escaping character
        # Another better way of doing this is "Sorry! Invalid entry. We can\'t add spy with the details you provided"

        print 'Sorry! Invalid entry. We can\'t add spy with the details you just provided. .'
    return len(friends)
Ejemplo n.º 17
0
def add_friend():
    #create a list to hold friend names,friend ages and friend rating
    new_friend = Spy('', '', 0, 0.0)

    new_friend.name = raw_input("Please add your friend's name: ")
    new_friend.salutation = raw_input("Are they Mr. or Ms.?: ")

    new_friend.name = new_friend.salutation + " " + new_friend.name
    #ask the user age
    new_friend.age = raw_input("Age?")
    new_friend.age = int(new_friend.age)
    #ask the user_rating
    new_friend.rating = raw_input("Spy rating?")
    new_friend.rating = float(new_friend.rating)
    #check condition if name is not empty ,age is gretaer than 12 and rating of the friend spy is greater than or equal to the user spy rating
    if len(new_friend.name
           ) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:
        friends.append(new_friend)
        #print the appropiate message
        print 'Friend Added!'
    else:
        print 'Sorry! Invalid rating entry. We can\'t add spy with the details you provided'

#return no of friends the user has
    return len(friends)
Ejemplo n.º 18
0
def add_friend():
    # The function should ask the user for the name, age and rating of their spy friend
    new_friend = Spy('','',0,0.0)

    # The function converts the data as appropriate
    new_friend.name = raw_input("Please add your friend's name: ")
    new_friend.salutation = raw_input("Are they Mr. or Ms.?: ")

    new_friend.name = new_friend.salutation + " " + new_friend.name

    new_friend.age = raw_input("Age?")
    new_friend.age = int(new_friend.age)

    new_friend.rating = raw_input("Spy rating?")
    new_friend.rating = float(new_friend.rating)

    # The function should add the friend to various lists only if name is not empty, age is greater than 12 and rating of the friend spy is greater than or equal to the user spy rating.
    if len(new_friend.name) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:
        friends.append(new_friend)
        print 'Friend Added!'
    # If any of the above conditions are not met it displays an appropirate message
    else:
        print 'Sorry! Invalid entry. We can\'t add spy with the details you provided'
    # The function should return and print the number of friends the user has
    return len(friends)
Ejemplo n.º 19
0
def add_friend():

    new_friend = Spy('','',0,0.0)

    new_friend.name = raw_input("enter  your friend's name: ")
    new_friend.salutation = raw_input("are they (Mr. or Ms. or Mrs.)?: ")
    if (new_friend.salutation == 'Mr.'):
        print 'he is a male'
    elif(new_friend.salutation == 'Ms.') or (new_friend.salutation == 'Mrs. '):
        print'she is a female'
    else:
        print 'please enter a valid salutation'

        new_friend.salutation = raw_input("are they (Mr. or Ms. or Mrs.)?: ")

    new_friend.name = new_friend.salutation + " " + new_friend.name

    new_friend.age = int(raw_input("Age? "))

    new_friend.rating = float(raw_input("Spy rating? "))

    if len(new_friend.name) > 0 and new_friend.age > 15 and new_friend.rating >= spy.rating:
        friends.append(new_friend)
        print 'Friend Added!'
    else:
        print 'Sorry! Invalid entry. We can\'t add spy with the details you provided'

    return len(friends)
Ejemplo n.º 20
0
def add_spy_friend():

    # Spy is a class
    new_spy_friend = Spy('', '', 0, 0.0)

    new_spy_friend.name = raw_input(
        colored("Please add your friend's name:", 'red'))
    new_spy_friend.salutation = raw_input(
        colored("Are they Mr. or Ms.?: ", 'red'))

    new_spy_friend.age = raw_input(colored("Age?", 'red'))
    new_spy_friend.age = int(new_spy_friend.age)

    new_spy_friend.rating = raw_input(colored("Spy rating?", 'red'))
    new_spy_friend.rating = float(new_spy_friend.rating)

    if len(
            new_spy_friend.name
    ) > 0 and new_spy_friend.age > 12 and new_spy_friend.rating >= spy.rating:
        friends.append(new_spy_friend)
        print colored('Friend Added', 'red')
        total_spy_friend()
    else:
        print colored(
            'Sorry! Invalid entry. We can\'t add spy with the details you provided',
            'red')

    return len(friends)
Ejemplo n.º 21
0
def add_friend():
    # Using the class spy
    new_friend = Spy(" ", " ", 0, 0.0)
    new_friend.name = raw_input("Please add your friend's name: ")
    new_friend.salutation = raw_input("Are they Mr. or Ms.?: ")

    # ask for the age of the friend
    new_friend.age = raw_input("Age?: ")
    # Type casting to integer
    new_friend.age = int(new_friend.age)

    # Ask for the rating of the friend
    new_friend.rating = raw_input("Spy rating?: ")
    # Type casting to float
    new_friend.rating = float(new_friend.rating)

    # Add a friend of correct age and equal or higher rating
    # Valid name of strings must be entered
    if len(new_friend.name) > 0 and new_friend.name.isdigit() == False and 12 < new_friend.age < 50 and new_friend.salutation.isalpha() == True and  new_friend.rating >= spy.rating :

        # After the conditions are satisfied the friend will be added
        friends.append(new_friend)
        print(colored('Friend Added!', "cyan"))
    else:
        print(colored("Sorry, the friend cannot be a spy!", "blue"))

    # The no of friends the spy has will be returned.
    return len(friends)
Ejemplo n.º 22
0
def add_friend():
    # initially setting details of friend to zero
    new_friend = Spy('', '', 0.0, 0)
    # asking the user to enter name
    new_friend.name = raw_input('Please tell your friend name:')
    # asking the user to enter salutation
    new_friend.salutation = raw_input('What should we call you Mr. or Ms.:')
    # asking the user to enter rating and converting it to float
    new_friend.rating = float(raw_input('Please tell your friends rating:'))
    # asking the user to enter age and converting it to integer
    new_friend.age = int(raw_input('Please tell your friends age:'))
    # check the standards of rating
    spy_rating(new_friend.rating)
    # checking the salutation
    # checks if user has right age to proceed, valid name and rating greater than user
    if 12 < new_friend.age < 50 and name_validation(new_friend.name) and 5 >= new_friend.rating >= spy.rating and \
            valid_salutation(new_friend.salutation):
        # stripping off spaces before and after his name
        new_friend.name = new_friend.name.strip(" ")
        new_friend.salutation = new_friend.salutation.strip(" ")
        # appending the new friend to friends list
        friends.append(new_friend)
        print 'Friend added'
    else:
        print 'Sorry we can\'t enter spy with that invalid details or your age might be low'
    # returning the no. of friends to the calling function
    return len(friends)
Ejemplo n.º 23
0
def add_friend():
    # friend_name = raw_input("Please enter your friend's name:")
    # fri = raw_input("Are they Mr. or Ms.?: ")
    # new_friend['name'] = new_friend['salu'] + " " + new_friend['name']
    # new_friend['age'] = input("What's the age?")
    # new_friend['rating'] = input("What is their spy rating?")

    newspy = Spy(
        raw_input("Please enter your friend's name:"),
        raw_input(
            "Are they Mr. or Ms.?: "),  #take all the imput for the friend
        input("What's the age?"),
        input("What is their Spy rating?"))
    if (newspy.name.isalpha() == True or newspy.name.isalnum()
            == True) and newspy.age > 12:  #vlaidation of their details
        friends.append(newspy)  #add the friend to the friendlist
        with open("friends.csv.txt", "a") as friends_data:
            writer = csv.writer(friends_data)
            writer.writerow(
                [newspy.name, newspy.salu, newspy.age, newspy.rating,
                 True])  #write friend detials into the friend.csv file
        print "Friend Added !!"
    else:
        print "Sorry ! but we can't add this spy to your friend list. "

    return len(friends)  #return the new length of the friend list
Ejemplo n.º 24
0
def load_friends():
    with open('friends.csv', 'rb') as friends_data:
        reader = csv.reader(friends_data)

        for row in reader:
            spy = Spy(row[0], row[1], row[2], row[3])
            friends.append(spy)
Ejemplo n.º 25
0
def load_frnds():
    with open('friends.csv', 'rb') as friends_data:
        reader = csv.reader(friends_data)

        for row in reader:
            frnd  = Spy(name=row[0],salutation=row[1],age=row[3],rating=row[2])
            friends.append(frnd)
Ejemplo n.º 26
0
def loadFriends():
    with open("friends.csv.txt", "rb") as friends_list:
        reader = list(csv.reader(friends_list))

        for row in reader[1:]:
            spy1 = Spy(row[0], row[1], row[2], row[3])
            friends.append(spy1)
Ejemplo n.º 27
0
def load_friends():
    with open('friends.csv', 'rU') as friends_data:
        reader = csv.reader(friends_data,delimiter=',', quotechar='"')

        for row in reader:
            spy = Spy(row[0],row[1],row[2],row[3])
            friends.append(spy)
Ejemplo n.º 28
0
def load_frnds():
    with open('friends.csv', 'rb') as friends_data:
        reader = list(csv.reader(friends_data))

        for row in reader[1:]:
            spy = Spy(name=row[0],salutation=row[1],age=row[3],ratings=row[2])
            friends.append(spy)
Ejemplo n.º 29
0
def add_friend():
    frnd_name = raw_input("Enter your friend name: ")
    frnd_salutation = raw_input("Mr. or Ms. : ")
    frnd_name = frnd_salutation + " " + frnd_name
    frnd_age = input("Enter the age of your friend : ")
    frnd_rating = input("Enter the rating of your friend : ")
    frnd_is_online = True
    if len(frnd_name
           ) > 2 and 50 >= frnd_age >= 12 and frnd_rating >= spy.rating:
        f = Spy(frnd_name, frnd_age, frnd_rating, frnd_is_online)
        # Appending new friend to list
        friends.append(f)
        t = datetime.now()
        print "Your friend has been Successfully added on :" + t.strftime(
            "%d/%m/%y")
        with open('friends.csv', 'a') as friends_data:
            writer = csv.writer(friends_data)
            writer.writerow([f.name, f.rating, f.age, f.is_online])
            # If validation fails
    else:
        # If validation fails
        print(colored("Alert! Friends with these values cant be added ",
                      "red"))
        # Returning the number of friends
    return len(friends)
Ejemplo n.º 30
0
def add_friend():  #Function to add a friend.

    new_friend = Spy('', '', 0, 0.0)  #Creating object for class 'Spy'

    name = raw_input("Enter friend's name: ")  #taking input.
    salutation = raw_input("Enter friend's salutation: ")
    new_friend.age = int(raw_input("Enter friend's age: "))
    new_friend.rating = float(raw_input("Enter friend's rating: "))
    count = 0
    for i in name:  #checking valid name or not.
        if name.isdigit() or name == "" or name.isspace(
        ):  #Checking for valid name input.:
            count = count + 1
    if count != 0:
        print "\nWARNING: Invalid name entented"
    count1 = 0
    for i in salutation:  #checking valid salutation or not.
        if salutation.isdigit() or salutation == "" or salutation.isspace(
        ):  #Checking for valid salutation input.
            count1 = count1 + 1
    if count1 != 0:
        print "\nWARNING: Invalid saluation entented"
    if count == 0 and count1 == 0:
        if old == 1:
            if name != "" and 12 < new_friend.age < 50 and new_friend.rating >= spy.rating and new_friend.rating <= 5 and salutation != "":
                new_friend.name = name
                new_friend.salutation = salutation
                friends.append(new_friend)
                print "New friend added."
            else:  #checking all corner cases.
                if new_friend.rating < 0 or new_friend.rating > 5:
                    print "Friend's rating entered is not eligible"
                elif new_friend.rating < spy.rating:
                    print "Friend's rating is less than the spy rating."
                elif new_friend.age <= 12 or new_friend.age >= 50:
                    print "Friend's age is not eligible."
                elif new_friend.salutation == "":
                    print "Friend's salutation cannot be left empty."
                elif new_friend.name == "":
                    print "Friend's name cannot be left empty."

        elif old == 0:  #if user selects for the new user, then we check the rating with the new user's rating with friend's rating.
            if name != " " and 12 < new_friend.age < 50 and new_friend.rating >= spy.rating and new_friend.rating <= 5 and salutation != "":
                new_friend.name = name
                new_friend.salutation = salutation
                friends.append(new_friend)
                print "New friend added."
            else:
                if new_friend.salutation == "":
                    print "Friend's salutation cannot be left empty."
                elif new_friend.age <= 12 or new_friend.age >= 50:
                    print "Friend's age is not eligible."
                elif new_friend.rating < new_spy.rating:
                    print "Friend's rating is less than the spy rating."
                elif new_friend.name == "":
                    print "Friend's name cannot be left empty."
    return len(friends)  #For number of friends.
Ejemplo n.º 31
0
def load_frnd():#loading friends in front of user when he sends the message

    with open('friends.csv','rU') as friends_data:
        reader = list(csv.reader(friends_data))

        for row in reader[1:]:
            spy=Spy(name=row[0], salutation=row[1], age=int(row[2]), rating=float(row[3]))
            friends.append(spy)