|
8 | 8 | p=1
|
9 | 9 | new_entry = []
|
10 | 10 |
|
11 |
| - |
12 | 11 | while True:
|
13 | 12 | print('''\nWelcome to our contact database, please select from the following options:
|
14 | 13 | To create new user enter "create":
|
|
65 | 64 | fin.close()
|
66 | 65 | elif chg.lower() == 'phone':
|
67 | 66 | chg = input('Whats the new phone? ')
|
68 |
| - lines[1] = chg |
| 67 | + data = data.replace(lines[1], chg) |
| 68 | + fin.close() |
| 69 | + fin = open('contacts.csv', 'wt') |
| 70 | + fin.write(data) |
| 71 | + fin.close() |
69 | 72 | elif chg.lower() == 'state':
|
70 | 73 | chg = input('Whats the new state? ')
|
71 |
| - lines[2] = chg |
| 74 | + data = data.replace(lines[2], chg) |
| 75 | + fin.close() |
| 76 | + fin = open('contacts.csv', 'wt') |
| 77 | + fin.write(data) |
| 78 | + fin.close() |
72 | 79 | elif chg.lower() == 'spirit animal':
|
73 | 80 | chg = input('Whats the new spirit animal? ')
|
74 |
| - lines[3] = chg |
| 81 | + data = data.replace(lines[3], chg) |
| 82 | + fin.close() |
| 83 | + fin = open('contacts.csv', 'wt') |
| 84 | + fin.write(data) |
| 85 | + fin.close() |
75 | 86 | else:
|
76 | 87 | print('not a valid option')
|
77 | 88 | lines = (',').join(lines)
|
78 |
| - |
79 |
| - |
80 |
| - |
81 |
| - # data = data.replace() |
82 |
| - # for l in lines: |
83 |
| - # if n.lower() in l.lower(): |
84 |
| - # print(f'Contact {l} found.') |
85 |
| - # spl = l.split(',') |
86 |
| - # upd = input('What needs updating, name, phone, state, spirit animal? ') |
87 |
| - # if upd.lower() == 'name'.lower(): |
88 |
| - # spl[0] |
89 |
| - |
| 89 | + elif a.lower() == 'delete': |
| 90 | + print('What contact do you want to delete? ') |
| 91 | + n = input('Enter name: ') |
| 92 | + fin = open('contacts.csv', 'rt') |
| 93 | + data = fin.read() |
| 94 | + if n.lower() in data.lower(): |
| 95 | + print(f'User {n.title()} found') |
| 96 | + for num, lines in enumerate(data.split('\n')): |
| 97 | + print(num, lines) |
| 98 | + if n.lower() in lines.lower(): |
| 99 | + lines = lines.split(',') |
| 100 | + # lines = ','.join(lines) |
| 101 | + print(lines) |
| 102 | + chg = input(f'Is this the entry you wish to delete?(y/n) ') |
90 | 103 |
|
91 | 104 |
|
92 |
| -# print(spl) |
93 |
| - # n = input('what name are we looking for: ') |
94 |
| - # if n.lower() in l[0].lower(): |
95 |
| - # spl = l.split(',') |
96 |
| - # spl_a = spl.copy() |
97 |
| - # print(f'{l} \nis the info on file, what needs to change:\nname,phone,state,spirit animal? ') |
98 |
| - # a = input('Enter what to change: ') |
99 |
| - # if a.lower() == 'name': |
100 |
| - # nchg = input('What do you want to change the name to? ') |
101 |
| - # print(spl_a) |
102 |
| - |
103 | 105 |
|
104 |
| - # if a.lower() == 'name': |
105 |
| - |
106 |
| -# n = input('enter a name: ') |
107 |
| -# new_entry.append(n) |
108 |
| -# ph = input('enter a phone number: ') |
109 |
| -# new_entry.append(ph) |
110 |
| -# st = input(f'enter {n}\'s state: ') |
111 |
| -# new_entry.append(st) |
112 |
| -# sa = input(f'enter {n}\'s spirit animal: ') |
113 |
| -# new_entry.append(sa) |
114 |
| -# j = ','.join(new_entry) |
115 |
| -# with open('contacts.csv', 'a') as file: |
116 |
| -# file.write(f'\n{j}') |
117 |
| -# with open('contacts.csv', 'a') as file: |
118 |
| -# new_entry = str(new_entry) |
119 |
| -# contacts.csv.write(new_entry) |
120 | 106 |
|
121 |
| -# contacts=[] |
122 |
| -# keys=[] |
123 |
| -# ncontacts=[] |
124 |
| -# dic={} |
125 |
| -# p=1 |
126 |
| -# new_entry = [] |
127 | 107 |
|
128 | 108 | with open('contacts.csv', 'r') as file:
|
129 | 109 | lines = file.read().split('\n')
|
|
0 commit comments