-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
46 lines (41 loc) · 1.06 KB
/
__init__.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
import fileinput
import linecache
import json
def init(dbs):
global DBs
DBs = dbs
global Cache
Cache = {}
for db in dbs:
Cache[db] = {}
def Readline(Database: str, Line: int):
try:
Cached = Cache[Database][Line]
return Cached
except:
try:
Read = json.loads(linecache.getline(Database, Line+1))
Cache[Database][Line] = Read
return Read
except:
return None
def Write(Database: str, Object):
try:
Writefile = open(Database, 'a')
Writefile.write(json.dumps(Object))
Writefile.close()
except:
pass
def Update(Database: str, Line: int, Object):
Readfile = open(Database, 'r')
Writefile = open(Database[0:Database.index('.')]+'.bak', 'w')
i = -1
while True:
i += 1
Read = Readfile.readline()
if Read == '':
break
if i == Line:
Writefile.write(json.dumps(Object))
else:
Writefile.write(Read)