|
7 | 7 | dic={}
|
8 | 8 | p=1
|
9 | 9 | new_entry = []
|
10 |
| -n = input('enter a name: ') |
11 |
| -new_entry.append(n) |
12 |
| -ph = input('enter a phone number: ') |
13 |
| -new_entry.append(ph) |
14 |
| -st = input(f'enter {n}\'s state: ') |
15 |
| -new_entry.append(st) |
16 |
| -sa = input(f'enter {n}\'s spirit animal: ') |
17 |
| -new_entry.append(sa) |
18 |
| -with open('contacts.csv', 'a') as file: |
19 |
| - for x in new_entry: |
20 |
| - file.write(f'\nx') |
| 10 | + |
| 11 | + |
| 12 | +while True: |
| 13 | + print('''\nWelcome to our contact database, please select from the following options: |
| 14 | +To create new user enter "create": |
| 15 | +To retrive an existing record enter "search": |
| 16 | +To update an existing record enter "update": |
| 17 | +To delete a record, enter "delete": |
| 18 | +When finished, enter"done":''') |
| 19 | + a = input("Enter: ") |
| 20 | + if a.lower() == 'done': |
| 21 | + False |
| 22 | + break |
| 23 | + |
| 24 | + elif a.lower() == 'create': |
| 25 | + print('\nYou selected to enter a new user follow the commands') |
| 26 | + n = input('enter a name: ') |
| 27 | + new_entry.append(n) |
| 28 | + ph = input('enter a phone number: ') |
| 29 | + new_entry.append(ph) |
| 30 | + st = input(f'enter {n}\'s state: ') |
| 31 | + new_entry.append(st) |
| 32 | + sa = input(f'enter {n}\'s spirit animal: ') |
| 33 | + new_entry.append(sa) |
| 34 | + j = ','.join(new_entry) |
| 35 | + with open('contacts.csv', 'a') as file: |
| 36 | + file.write(f'\n{j}') |
| 37 | + elif a.lower() == 'search': |
| 38 | + print('What user are you looking for?') |
| 39 | + n = input('enter name: ') |
| 40 | + with open('contacts.csv', 'r') as file: |
| 41 | + lines = file.read().split('\n') |
| 42 | + for l in lines: |
| 43 | + if n.lower() in l.lower(): |
| 44 | + print(f'User {n} found: \n---------------------------------------------\n{l}') |
| 45 | + print('---------------------------------------------') |
| 46 | + elif a.lower() == 'update': |
| 47 | + n = input('what name are we looking for: ') |
| 48 | + with open('contacts.csv', 'r') as file: |
| 49 | + lines = file.read().split('\n') |
| 50 | + for l in lines: |
| 51 | + spl = l.split(',') |
| 52 | + print(spl) |
| 53 | + if n.lower() in l.lower(): |
| 54 | + spl = l.split(',') |
| 55 | + spl_a = spl.copy() |
| 56 | + print(f'{l} \nis the info on file, what needs to change:\nname,phone,state,spirit animal? ') |
| 57 | + a = input('Enter what to change: ') |
| 58 | + if a.lower() == 'name': |
| 59 | + |
| 60 | + |
| 61 | + # if a.lower() == 'name': |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +# n = input('enter a name: ') |
| 72 | +# new_entry.append(n) |
| 73 | +# ph = input('enter a phone number: ') |
| 74 | +# new_entry.append(ph) |
| 75 | +# st = input(f'enter {n}\'s state: ') |
| 76 | +# new_entry.append(st) |
| 77 | +# sa = input(f'enter {n}\'s spirit animal: ') |
| 78 | +# new_entry.append(sa) |
| 79 | +# j = ','.join(new_entry) |
| 80 | +# with open('contacts.csv', 'a') as file: |
| 81 | +# file.write(f'\n{j}') |
| 82 | + |
21 | 83 |
|
22 | 84 |
|
23 | 85 | # with open('contacts.csv', 'a') as file:
|
|
30 | 92 | contacts.append(l.split(','))
|
31 | 93 | for c in contacts[0]:
|
32 | 94 | keys.append(c)
|
33 |
| - contacts.append(new_entry) |
| 95 | + # contacts.append(new_entry) |
34 | 96 | while p < len(contacts):
|
35 | 97 | a = dic.copy()
|
| 98 | + b = contacts[p].copy() |
36 | 99 | for k in keys: # k is contacts[0](headers.csv) iterated over
|
37 |
| - for c in contacts[p]: # c is each contacts information iterated over |
38 |
| - x = contacts[p].index(c) |
39 |
| - contacts[p].pop(x) |
| 100 | + for c in b: |
| 101 | + x=b.index(c) |
| 102 | + b.pop(x) |
40 | 103 | a[k] = c
|
41 | 104 | break
|
42 | 105 | p+=1
|
|
0 commit comments