Пример #1
0
def load_friends():
    with open('friends.csv', 'rb') as friends_data:
        reader = list(csv.reader(friends_data))

        for row in reader[1:]:
            if row:
                name = row[0]
                salutation = row[1]
                rating = row[2]
                age = row[3]
                spy = Spy(name, salutation, age, rating)
                friends.append(spy)
Пример #2
0
def load_frnd():  #for loading all the friend

    with open('friends.csv', 'rb') as friends_data:  #opening chats.csv file
        reader = list(csv.reader(friends_data))  #making this as a list

        for row in reader[
                1:]:  #Excepting the first value display all by use concept of slicing
            spy = Spy(name=row[0],
                      salutation=row[1],
                      age=row[3],
                      rating=row[2])  #object made of the classs
            friends.append(spy)  #appending it to the list
Пример #3
0
def load_friends():
    with open('friends.csv', 'rb') as friends_data:
        reader = list(csv.reader(friends_data))

        for row in reader[1:]:
            if row:
                name = row[0]
                age = row[1]
                rating = row[2]
                online = row[3]
                new_spy = Spy(name, age, rating, online)
                friends.append(new_spy)
Пример #4
0
def load_friend():
    read_object = open("spy_friends.csv", 'r')
    reader = csv.reader(read_object)
    for row in reader:
        name = row[0]
        salutation = row[1]
        age = int(row[2])
        rating = float(row[3])
        is_online = bool(row[4])
        new_friend = Spy(name, salutation, age, rating)
        friends.append(new_friend)
        print row
    read_object.close()
Пример #5
0
def load_friends():

    # opening file friends_database.csv in read mode
    with open('friends_database.csv', "r") as friends_data:
        read_object = csv.reader(friends_data)
        next(read_object)

        for line in read_object:
            spy = Spy(salutation=line[0],
                      name=line[1],
                      age=int(line[2]),
                      rating=float(line[3]))
            friend_list.append(spy)
Пример #6
0
def load_friends():
    with open('friends.csv',
              'rb') as friends_data:  # opening file friends.csv in read mode
        reader = csv.reader(friends_data)
        print 'your friend list is below:'

        for row in reader:
            spy = Spy(name=row[0],
                      salutation=row[1],
                      rating=float(row[2]),
                      age=int(row[3]))
            friends.append(spy)
            print row
Пример #7
0
def load_friends():
    read_object = open("test.csv", 'rb')
    reader = csv.reader(read_object)
    for row in reader:
        # order will be (name, salutation, age, friend_rating)
        name = row[0]
        salutation = row[1]
        age = int(row[2])
        friend_rating = float(row[3])
        is_online = bool(row[4])
        new_friend = Spy(name, salutation, age, friend_rating)
        friends.append(new_friend)
    read_object.close()
Пример #8
0
 def load_friends():
     with open('friends.csv', 'rU') as friends_data:
         reader = csv.reader(friends_data)
         for row in reader:
             try:
                 friends.append(
                     Spy(name=row[0],
                         salutation=(row[1]),
                         age=int(row[2]),
                         rating=float(row[3])))
             except IndexError:
                 pass
             continue
Пример #9
0
def add_friend():
    # using class spy
    new_friend = Spy(" ", " ", 0, 0.0)

    # ask user for name and salutation of friend
    new_friend.name = raw_input("Please add your friend's name: ")
    pattern_n = '^[a-zA-Z\s]+s'

    new_friend.salutation = raw_input("What to call Mr. or Ms.?: ")
    pattern_s = '^[a-zA-Z\s]+s'

    # concatination for full name
    new_friend.name = new_friend.salutation + " " + new_friend.name

    # ask for age of friend, int represents type casting in int
    new_friend.age = int(raw_input("Age? "))
    pattern_a = '^[0-9]+$'

    #ask for rating of friend, float represents type casting in float
    new_friend.rating = float(raw_input("Spy rating? "))
    pattern_r = '^[0-9]+\.[0-9]+$'

    # users input validations
    if len(new_friend.name) > 0 and new_friend.name.isdigit(
    ) == False and re.match(pattern_n, new_friend.name) != None and re.match(
            pattern_s, new_friend.salutation
    ) != None and new_friend.age > 12 and new_friend.rating < 50 and re.match(
            pattern_a,
            new_friend.age) != None and new_friend.salutation.isalpha(
            ) == True and new_friend.rating >= 0 and re.match(
                pattern_r, new_friend.rating) != None:

        # add friend if conditions satisfies
        friends.append(new_friend)
        print(colored('Friend Added!', 'magenta'))
    else:
        print(
            colored(
                'Sorry! Invalid entry. We can\'t add spy with the details you provided\n ',
                'blue'))
    print(colored('The convention to follow is: \n ', 'blue'))
    print(colored('1. Name can be alphabets only.\n ', 'blue'))
    print(colored('2. Age can be digits only.\n ', 'blue'))
    print(
        colored(
            '3. Do not use (.) after salutation, it can be alphabets only too.\n ',
            'blue'))
    print(colored('Keep in mind and Try Again\n\n ', 'blue'))

    # returning total no of friends.
    return len(friends)
Пример #10
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.
Пример #11
0
def add_friend():
    # Using the class spy
    new_friend = Spy(" ", " ", 0, 0.0)
    while True:
        new_friend.name = raw_input("Please add your friend's name:- ")
        if len(new_friend.name) > 0:
            while True:
                new_friend.salutation = raw_input("Are they Mr. or Ms. ?:- ")
                if len(new_friend.salutation) > 0:
                    if (new_friend.salutation == 'ms.'
                            or new_friend.salutation == 'Ms.'
                            or new_friend.salutation == "Mr."
                            or new_friend.salutation == "mr."):
                        # ask for the age of the friend
                        while True:
                            new_friend.age = raw_input("Age?:- ")

                            # Type casting to integer
                            if len(new_friend.age) > 0:
                                new_friend.age = int(new_friend.age)
                                if 18 < new_friend.age < 50:
                                    # After the conditions are satisfied the friend will be added
                                    friends.append(new_friend)
                                    print(colored('FRIEND ADDED!', "magenta"))

                                else:
                                    print(
                                        colored(
                                            "Sorry but your age is not valid for spy!",
                                            'red'))
                                    print(
                                        colored("       THANK YOU!       ",
                                                'yellow'))
                                    exit()
                                return len(friends)
                                #application will terminate
                                # The no of friends the spy has will be returned.
                                # The no of friends the spy has will be returned.
                            else:
                                print(
                                    colored("Sorry but age cannot be blank!",
                                            'red'))

                        # The no of friends the spy has will be returned.
                    else:
                        print(colored('Please enter valid salutation!', 'red'))
                else:
                    print(colored('Salutation cannot be blank!', 'red'))
        else:
            print(colored('Name cannot be blank!', 'red'))
            return len(friends)
Пример #12
0
def add_friend():


    new_friend = Spy('', '', 0, 0.0)
    new_friend.salutation = raw_input("Are you Mr. OR Ms.:")
    new_friend.name= raw_input("please add your friends name:")
    new_friend.rating=float(raw_input("Enter your friendz  rating:"))
    new_friend.age=int(raw_input("Enter your age please:"))
    if len(new_friend.name) > 0 and new_friend.age > 12 and new_friend.rating >= 1.0:
        friends.append(new_friend)
        print 'Friend Added!'
    else:
        print "Invalid entry!!!!!! .you canot add spy with above details"
    return len(friends)
Пример #13
0
def add_friend():
    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
    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 > 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'

    return len(friends)
Пример #14
0
def add_friend():
    frnd=Spy('','',0,0.0)  #to add a new friend
    frnd.name = raw_input('What is your friend \'s name? ')
    frnd.sal = raw_input("What should we call your friend?")
    frnd.age = input('What is your friend\'s age ? ')
    frnd.ratings = input('What is your friend\'s rating ?')
    frnd.is_online= True
    if len(frnd.name)>2 and 14<frnd.age<60 and frnd.ratings>spy.ratings:  # conditons for adding new friend
        friends.append(frnd) #adding this new friend in the list of already existing friends
        with open('friends.csv','a') as friends_data:
            writer = csv.writer(friends_data)
            writer.writerow([frnd.name, frnd.sal, frnd.ratings, frnd.age, frnd.is_online])
    else:
        print "Friend cannot be added."
    return len(friends)  # will return to add_friend()
Пример #15
0
def add_friend(): #function for adding a new friend to the list friends
    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.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)
    if len(new_friend.name) > 0 and new_friend.age > 12 and new_friend.rating > spy.rating:#conditions for being a spy friend
        friends.append(new_friend)
        print "Friend Added!"
    else:
        print "Sorry!your friend cant be a spy!!"

    return len(friends)
Пример #16
0
def add_friend():
    frnd=Spy('','',0,0.0)
    frnd.sal=raw_input('what should we call you?')
    frnd.name=raw_input('Enter your name: ')
    frnd.age=input('what is your age? ')
    frnd.rating=input('what is your rating? ')
    frnd.is_online=True
    if len(frnd.name)>2 and 12<frnd.age<50 and frnd.rating>spy.rating:
        friends.append(frnd)
        with open('friends.csv','a') as friends_data:
            writer=csv.writer(friends_data)
            writer.writerow([frnd.name,frnd.sal,frnd.age,frnd.rating,frnd.is_online])
            print'Your friend is added successfully..'
    else:
        print'Friend cannot be added'
    return len(friends)
Пример #17
0
            def add_freind():
                new_friend = Spy(' ', ' ', 0, 0.0)
                new_friend.name = raw_input("What\'s your friend name?")
                new_friend.salutation = raw_input('Are they Mr.or Mrs?')
                new_friend.age = int(raw_input('Age?'))
                new_friend.rating = float(raw_input('spy_rating'))
                print 'Welcome to Spy Chat' + ' ' + new_friend.salutation + ' ' + new_friend.name
                if len(new_friend.name) > 0 and new_friend.age > 12:
                    print 'CONGRAS New Friend Added!'
                else:
                    print 'Invalid Entry!'
                friends.append(new_friend)
                print new_friend.name
                for temp in friends:

                    print temp.name
Пример #18
0
def add_friend():
    #new_friend = {"Name": "", "Salutation": "", "age": 0, "Rating": 0.0, "Chats": [] }
    Name=raw_input("Whats your friend spy name?")
    Salutation=raw_input("what would be the salutation, Mr. or Ms.??")
    #Name= new_friend["Salutation"] + " " + new_friend["Name"]
    age = int(input("what is friends age?"))
    Rating= float(input("what's your friend spy rating??"))
    if len(Name) > 0 and 12 < age < 50:  # add friend
        spy=Spy(Name,Salutation,age,Rating)
        Friends.append(spy)
        with open('friends.csv', 'a') as friends_data:
            writer = csv.writer(friends_data)
            writer.writerow([spy.Name, spy.Salutation, spy.age, spy.Rating, spy.is_online])
    else:      #####invalid details
        print("Sorry we can't add your friend's details please try again.")
    return len(Friends)
Пример #19
0
    def add_friend():
        new_friend = Spy('','',0,0.0)

        new_friend.name = raw_input("Please add your friend's name: ")
        new_friend.salutation = raw_input("Are the Mr. or Mrs.?: ")
        new_friend.name = new_friend.name+' '+new_friend.salutation
        new_friend.age = int(raw_input('Age?'))
        new_friend.rating = float(raw_input('enter your 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'
        else:
            print "Sorry! Invaid entry. We can't add spy with the details you provided"
        # here this return len will return the no for frineds the user have means the no of elements in the list
        return len(friends)
Пример #20
0
def add_friend():  #defining function add_friend()
    frnd = Spy('', '', 0, 0.0)  #using spy class
    frnd.name = raw_input('What is your friend name? ')
    frnd.salutation = raw_input('What should we call you (Mr. or Ms.)?')
    frnd.age = input('What is your friend age ? ')
    frnd.rating = input('What is your friend rating ?')
    if len(frnd.name) > 2 and 20 < frnd.age < 50 and frnd.rating > spy.rating:
        with open('friends.csv', 'a') as friends_data:
            writer = csv.writer(friends_data)
            writer.writerow([
                frnd.name, frnd.salutation, frnd.rating, frnd.age,
                frnd.is_online
            ])
    else:
        print "Friend cannot be added."
    return len(friends)
Пример #21
0
def add_friend():

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

    new_friend.name = raw_input("Please add your friend's name: ")
    pattern_n = '^[a-zA-Z\s]+s'

    new_friend.salutation = raw_input(
        "What u want me to call you, Mr. or Ms.?: ")
    pattern_s = '^[a-zA-Z\s]+s'

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

    new_friend.age = int(raw_input("ur age? "))
    pattern_a = '^[0-9]+$'

    new_friend.rating = float(raw_input(" ur Spy rating? "))
    pattern_r = '^[0-9]+\.[0-9]+$'

    if len(new_friend.name) > 0 and new_friend.name.isdigit(
    ) == False and re.match(pattern_n, new_friend.name) != None and re.match(
            pattern_s, new_friend.salutation
    ) != None and new_friend.age > 12 and new_friend.rating < 50 and re.match(
            pattern_a,
            new_friend.age) != None and new_friend.salutation.isalpha(
            ) == True and new_friend.rating >= 0 and re.match(
                pattern_r, new_friend.rating) != None:

        friends.append(new_friend)
        print(colored('Friend Added!', 'red'))
    else:
        print(
            colored(
                'Sorry! Invalid entry. We can\'t add spy with the details you provided\n ',
                'blue'))
    print(colored('The convention to follow is: \n ', 'blue'))
    print(colored('1. Name can be alphabets only.\n ', 'blue'))
    print(colored('2. Age can be digits only.\n ', 'blue'))
    print(
        colored(
            '3. Do not use (.) after salutation, it can be alphabets only too.\n ',
            'blue'))
    print(colored('Keep in mind and Try Again\n\n ', 'blue'))

    return len(friends)
Пример #22
0
def add_friend():  # function to add friend
    # taking friends detail s input
    frnd = Spy ('','',0,0.0)
    frnd = {'name': "",'age':0,'ratings':0.0,'isonline':True,'chats':[]}  # dictionary for details of friend
    frnd.name =raw_input("What is your friend's name : ")
    frnd.sal = raw_input("What should we call you")
    frnd.age=input("What is the age :")
    frnd.rating=input("What are the ratings : ")
    frnd.is_online = True
    if len(frnd.name)>0 and 12<frnd.age<50 and frnd.rating>spy.rating: # checking for spy details
        # adding the details in the respective lists
        friends.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])
    else:
        print "The friend cannot be added "
    return len(friends)  # returning length of list friend_name
Пример #23
0
def add_friend():
    new_friend = Spy(" ", " ", 0, 0.0)
    new_friend.name = input("Please add your friend's name: ")
    new_friend.salutation = input("Are they Mr. or Ms.?: ")

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

    new_friend.age = int(input("Age?"))
    # new_friend.rating = float(input("Spy rating?"))
    check_age(c_age=new_friend.age,
              c_name="friend",
              check_rating=new_friend.rating)
    friends.append(new_friend)
    print('Friend Added!')

    print('You have %d friends' % len(friends))

    start_chat(spy_name, spy_age, spy_rating)
Пример #24
0
def add_friend():  #adding a new friend
    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
    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)
    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"
        invalid_friend = 1

    return len(friends)
Пример #25
0
def add_a_friend():
    friend_name = input("What is your friend's name: ")
    if len(friend_name) > 0:
        friend_salutation = input("What should we call your friend (Mr or Ms): ").capitalize()
        friend_age = int(input("Age: "))
        if check_spy_eligibility(friend_age):
            friend_rating = float(input("Enter the rating: "))
            if friend_rating >= spy.rating:
                friend = Spy(friend_name, friend_salutation, friend_age, friend_rating)
                spy.add_spy_friend(friend)
                print("Friend added!")
            else:
                print("Your friend has lower rating than you and we can't allow that")
        else:
            print("Age is not valid")
    else:
        print("You didn't entered a valid name")
    return len(spy.friend_list)
Пример #26
0
def add_friend():

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

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

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

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

    new_friend.rating = 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!')
Пример #27
0
def add_friend():
   new_friend=Spy('','',0,0.0)
   new_friend.name = raw_input("Add your friend's name:\n")
   new_friend.salutation= raw_input("Are they Mr. or Ms.? \n")
   new_friend.name = new_friend.salutation + " " + new_friend.name
   new_friend.age = raw_input("Age?\n")
   new_friend.rating = raw_input("Spy rating?\n")
   #int() method, it converts strings into integers.
   new_friend.age =int(new_friend.age)
   #float() method ,it convert strings into floats
   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'
   return len(friends)
Пример #28
0
def add_friend():
    new_friend = Spy("", "", 0, 0.0)

    #enter data of friend
    new_friend.name = raw_input("Enter the name of the friend : ")
    new_friend.salutation = raw_input("Enter salutation of your friend : ")
    new_friend.name = new_friend.salutation + " " + new_friend.name
    new_friend.age = int(raw_input("Enter the age of your friend : "))
    new_friend.rating = float(raw_input("Enter the rating of your friend : "))

    #condition to be a spy friend
    if len(new_friend.name
           ) > 0 and new_friend.age > 12 and new_friend.age < 50:
        friends.append(new_friend)
        print "You are now friend with %s" % (new_friend.name)
    else:
        print "Friend with this data can not be added"
    return len(friends)
Пример #29
0
def add_friend():

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

    try:
        friend_name = raw_input('Please add your friend\'s name: ')
        try:
            if len(friend_name > 0):
                new_friend.name = friend_name
                friend_salutation = raw_input('Are they Mr. or Ms.?: ')
                try:
                    if friend_salutation is 'Mr.' or 'Ms.' or 'Dr.' or 'Kr. ' or 'Er. ':
                        new_friend.salutation = friend_salutation
                        new_friend.name = new_friend.salutation + ' ' + new_friend.name
                        friend_age = int(raw_input('Age?'))
                        try:
                            if type(friend_age
                                    ) is int and 12 < friend_age < 100:
                                new_friend.age = friend_age
                                friend_rating = float(raw_input('Spy rating?'))
                                try:
                                    if type(
                                            friend_rating
                                    ) is float and 0 < friend_rating <= 5:
                                        new_friend.rating = friend_rating
                                except Exception:
                                    print 'Error: Enter correct rating of friend'
                        except Exception:
                            print 'Error: Enter correct age of friend'
                except Exception:
                    print 'Error: Enter correct salutation of friend'
        except Exception:
            print 'Error: Enter correct name of friend'
    except Exception:
        print 'Error valid details of friend'

    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'

    return len(friends)
Пример #30
0
def add_friend():
	# initialising spy object
	friend = Spy('','', 0,0)
	# getting credentials
	friend.name= raw_input("Input a new friend name : ")
	friend.salutation = raw_input("Is new friend Mr. or Ms.  :")
	friend.age = int(raw_input("Input his age  :"))
	friend.rating = float(raw_input("Input his rating  :"))

	# Checking Validity of new friend
	if len(friend.name)>0 and 18<=friend.age<=40 and spy.rating<=friend.rating<=5.0:

		friends.append(friend)
		print "\n"+friend.salutation+" "+friend.name+" with age "+str(friend.age)+" and rating "+str(friend.rating)+" added to your friend\'s list\n"

	else :
		print "This man is not qualified enough to be a friend. \n"	

	return len(friends)