예제 #1
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 = raw_input("Age?")
    new_friend.rating = raw_input("Spy rating?")

    #To check the constraints of adding a new friend
    if len(new_friend.name
           ) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:
        if (new_friend.salutation == 'ms.' or new_friend.salutation == 'mr.'
                or new_friend.salutation == 'Mr.'
                or new_friend.salutation == 'Ms.'):
            friends.append(new_friend)
            with open('friends.csv', 'a') as friends_data:
                writer = csv.writer(friends_data)
                writer.writerow([
                    spy.name, spy.saluation, spy.rating, spy.age, spy.is_online
                ])
    else:
        print(
            'Sorry! Invalid entry. We can\'t add spy with the details you provided'
        )
    return len(friends)
예제 #2
0
파일: main.py 프로젝트: vicky721050/Spychat
def add_friend():

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

    new_friend.name = raw_input('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('Enter the Age of your friend'))
    new_friend.rating = float(raw_input('enter rating of your friend'))

    #Here we are checking the age of the new 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 colored('Sorry! We can\'t add this friend to your friends list',
                      'red')

    return len(friends)
예제 #3
0
def load_friends():
    with open('friends.csv', 'rb') as friends_data:
        read = csv.reader(friends_data)
        for row in read:
            spy = Spy(name=row[0],
                      salutation=row[1],
                      rating=row[2],
                      age=row[3],
                      is_online=row[4])
            add_friends.append(spy)
예제 #4
0
def load_friends():
    with open('friends.csv', 'rb') as friends_data:
        reader = csv.reader(friends_data)
        for row in reader:
            spy = Spy(name=row[0],
                      salutation=row[1],
                      rating=float(row[2]),
                      age=int(row[3]))
            friends.append(spy)
            print(friends)
예제 #5
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
예제 #6
0
def add_friend():
    new_friend = Spy(" ", " ", 0, 0.0)

    new_friend.name = raw_input("enter you friend_name:")
    new_friend.salutation = raw_input("Mr. or Ms. :")
    new_friend.age = int(raw_input("what is age of your friend:"))
    new_friend.rating = float(raw_input("what is rating of your friend:"))
    if len(new_friend.name
           ) > 0 and new_friend.age > 17 and new_friend.rating > 0:

        friends.append(new_friend)
        with open("friends.csv", "a") as friends_data:
            writer = csv.writer(friends_data)
            writer.writerow([
                new_friend.name, new_friend.salutation, new_friend.age,
                new_friend.rating, new_friend.is_online
            ])

    else:
        print("Please enter right details")

    return len(friends)
예제 #7
0
파일: main.py 프로젝트: vicky721050/Spychat
                    number_of_friends = add_friend()
                    print 'You have %d friends' % (number_of_friends)
                elif menu_choice == 3:
                    send_message()
                elif menu_choice == 4:
                    read_message()
                elif menu_choice == 5:
                    read_chat_history()
                else:
                    show_menu = False
    else:
        print 'Sorry you are not of the correct age to be a spy'


#This is for the existing one, when we enter the existing user
if existing == 'Y':
    start_chat(spy)
else:
    spy = Spy('', '', 0, 0.0)
    spy.name = raw_input('Welcome to the program, Can I Have your Name Please')

    #here we are checking the length of the
    if len(spy.name) > 0:
        spy.salutation = raw_input('What i call you Mr. or Ms.')
        spy.age = int(raw_input('May i have your age please'))
        spy.rating = float(raw_input('your rating please'))
        spy_Online = True
        start_chat(spy)
    else:
        print ' enter a valid name'
예제 #8
0
                select_a_friend()
            else:
                show_menu = False


def read_chats():
    with open('chats.csv', 'rb') as chats_data:
        read = csv.reader(chats_data)
        for row in read:
            print row


if existing == "Y":
    start_chat(spy)
else:
    spy = Spy('', '', 0, 0.0)

    spy.name = raw_input("What is your name?")

    if len(spy.name) > 0:
        print("Welcome " + spy.name + ". Glad to have you back with us.")
        spy.salutation = raw_input("What should we call you (Mr. or Ms.)?")
        spy.name = spy.salutation + " " + spy.name
        print(
            "Alright " + spy.name +
            ". I'd like to know a little bit more about you before we proceed..."
        )
        spy.age = 0
        spy.rating = 0.0
        spy.is_online = False
        spy.age = raw_input("What is your age?")
예제 #9
0
            print("Invalid option select from 1 to 6")
            exit()


# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#                                       Code for continuing as a new user
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

print("Hi!%s. %s" % (spy.salutation, spy.name))
user_option = raw_input(
    "Would you like to continue as a default user (default) or create your own (new)? "
)  # type of user

# if user creates a new spy entry
if user_option == "new":
    spy = Spy(" ", "", 0, 0.0)
    spy.name = raw_input(
        "Welcome to SpyChat, you must tell me you Spyname first:")

    # to calculate the length of the string
    if len(spy.name) > 0 and spy.name.isdigit() == False:
        #asking for salutation
        print('Welcome ' + spy.name + ' Glad to have you with us.')
        if len(spy.salutation) > 0:
            spy.salutation = raw_input("What should I call you Mr. or Ms. ?")
            print(
                'Alright ' + spy.salutation + '.' + spy.name +
                ' I\'d like to know a little bit more about you before we proceed'
            )

            # asking for the age of spy