-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrud.py
73 lines (68 loc) · 1.77 KB
/
crud.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
72
73
import json ,os
print("1.Insert \n 2.Update \n 3.Delete \n 4.Get")
def insert():
if(os.path.exists("crud.json")):
f=open("crud.json","r")
b=json.load(f)
c={}
c["Name"]=input("Enter the name: ")
c["Email"]=input("Enter the Email: ")
c["Password"]=input("Enter the password: ")
b.append(c)
ff=open("crud.json","w")
json.dump(b,ff,indent=4)
print("data inserted")
else:
b=[]
c={}
c["Name"]=input("Enter the name: ")
c["Email"]=input("Enter the Email: ")
c["Password"]=input("Enter the password: ")
b.append(c)
ff=open("crud.json","w")
json.dump(b,ff,indent=4)
print("data inserted")
def update():
aa=open("crud.json","r")
ff=json.load(aa)
n=input("Insert the Email: ")
cc=0
for i in ff:
if i["Email"]== n:
g={}
g["Name"]=input("Enter the Name : ")
g["Password"]=input("Enter the password : ")
g["Email"]=n
ff[cc]=g
f=open("crud.json","w")
json.dump(ff,f,indent=4)
print("data inserted")
break
cc+=1
else:
print("Invalid email")
def Delete():
aaa=open("crud.json","r")
ff=json.load(aaa)
length=len(ff)
m=input("Emter the Email : ")
dd=0
for i in ff:
if i["Email"]==m:
ff.remove(i)
if length==1:
os.remove("crud.json")
break
else:
file=open("crud.json","w")
json.dump(ff,file,indent=4)
break
else:
print("invalid Email")
a=int(input("Choose the option : "))
if a==1:
insert()
elif a==2:
update()
elif a==3:
Delete()