-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCrud operation .py
More file actions
74 lines (68 loc) · 2.33 KB
/
Crud operation .py
File metadata and controls
74 lines (68 loc) · 2.33 KB
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
72
73
74
import json
print("""
1) Insert
2) Update
3) Delete
""")
option = input("enter any option :-----")
if option == '1':
with open('crud.json','r') as l:
re=json.load(l)
contact=input('enter your contact :-----')
list1 = []
dict1={}
dict2={}
if list1 == re:
user_name = input('enter the name :---')
email = input("enter your email :--- ")
dict1['user name'] = user_name
dict1['email'] = email
dict2[contact] = dict1
re.append(dict2)
print("successfuly insert your detail !!!")
with open('crud.json','w+') as k:
json.dump(re,k,indent=4)
else:
for j in re:
if contact in j:
print('this account already exist')
break
else:
user_name = input('enter the name :---')
email = input("enter your email :--- ")
dict1['user name'] = user_name
dict1['email'] = email
dict2[contact] = dict1
re.append(dict2)
print('successfuly insert your detail !!!')
with open('crud.json','w+') as k:
json.dump(re,k,indent=4)
break
elif option == '2':
contact=input('enter the contact:---')
with open('crud.json','r') as l:
re=json.load(l)
for j in re:
if contact in j:
for y in j.values():
store = y
new_user = input("Enter your new user :- ")
new_email = input("Enter your new email :- ")
store["user name"]=new_user
store["email"]=new_email
print('successfuly update your detail !!!')
break
with open ("crud.json","w") as m:
json.dump(re,m,indent=4)
else:
contact=input('enter the contact:---')
with open('crud.json','r') as l:
re=json.load(l)
for j in re:
if contact in j:
ml=j
re.remove(ml)
print('seccessfuly delete your account !!!')
break
with open('crud.json','w') as n:
json.dump(re,n,indent=4)