-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_donation.py
73 lines (66 loc) · 2.06 KB
/
delete_donation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import msvcrt
import main
def delete_donor_from_csv_file():
found=0
del_according_ID = input('Add ID which you want to delete:').lower()
del_according_ID = del_according_ID.lower()
delete_from_csv = open("Data/donor.csv", "r+")
read_csv_line = delete_from_csv.readlines()
delete_from_csv.seek(0)
for i in read_csv_line:
splited=i.split(',')
if del_according_ID!=splited[7].lower():
delete_from_csv.write(i)
else:
found+=1
sure_about_delete(delete_from_csv,i)
delete_from_csv.truncate()
delete_from_csv.close()
if found==0:
print("ID not found")
print('1. New delete')
print('2. Back')
end_of_delete('donor')
def delete_donations_from_csv_file():
found=0
according_ID = input("Add ID which donation you want to delete:").upper()
according_ID = according_ID.upper()
delete_from_csv = open("Data/donations.csv", "r+")
read_cs_line = delete_from_csv.readlines()
delete_from_csv.seek(0)
for i in read_cs_line:
splited=i.split(',')
if according_ID!=splited[0]:
delete_from_csv.write(i)
else:
found+=1
sure_about_delete(delete_from_csv,i)
delete_from_csv.truncate()
delete_from_csv.close()
if found==0:
print("ID not found")
print('1. New delete')
print('2. Back')
end_of_delete('donation_event')
def sure_about_delete(delete_from_csv,i):
want_to_delete_ans = input('Are sure to delete it?(yes/no):')
if want_to_delete_ans.lower()=="yes":
pass
elif want_to_delete_ans.lower()=="no":
delete_from_csv.write(i)
else:
print("Yes or no!")
sure_about_delete(delete_from_csv,i)
def end_of_delete(kind):
get=msvcrt.getwch()
if get=='1':
if kind=='donor':
delete_donor_from_csv_file()
elif kind=='donation_event':
delete_donations_from_csv_file()
elif get=='2':
main.creat_menu()
return True
else:
print("Choose one!")
end_of_delete(kind)