Beispiel #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)
Beispiel #2
0
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)
Beispiel #3
0
def load_chats():
    with open('chats.csv', 'rb') as chats_data:
        reader = csv.reader(chats_data)
        for row in reader:
            new_chat = ChatMessage(message=row[0],
                                   time=row[1],
                                   sent_by_me=row[2])
            friends.append(new_chat)
            print(friends)
Beispiel #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)
Beispiel #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
Beispiel #6
0
def add_friends():
    new_friend = {'name': "", 'salutation': "", 'age': 0, 'rating': 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")

    if len(new_friend['name']) > 0 and int(new_friend['age']) < 50 and int(
            new_friend['age']) > 12 and float(new_friend['rating']) >= float(
                spy.rating):
        friends.append(new_friend)
        print "Congratulations! Your friends is been successfully added\n"
    else:
        print "Sorry we cannot add this friend he does'nt meet our criteria\n"
    return len(friends)
Beispiel #7
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)