-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase.py
43 lines (42 loc) · 970 Bytes
/
database.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
def upload(table,row,data,file="db.txt"):
try:
f = open(file, "r")
f.close()
except:
f = open(file,"w")
f.close()
f = open(file, "r")
database = f.read()
if database == "":
database = "{}"
database = eval(database)
f.close()
f = open(file,"w")
if not(table in database.keys()):
database[table] = {}
database[table][row] = data
f.write(str(database))
f.close()
def get(table="",row="",file="db.txt"):
f = open(file,"r")
database = eval(f.read())
f.close()
if table == "":
return database
elif row == "":
return database[table]
else:
return database[table][row]
def delete(file="db.txt"):
f = open(file,"w")
f.truncate()
f.close()
def exists(file="db.txt"):
try:
f=open(file,"r")
if f.read() != "":
return True
else:
return False
except:
return False