forked from bigfoot547/bigfootbot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb.py
40 lines (33 loc) · 971 Bytes
/
db.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
import os
import path
class puretext_db():
def __init__(self, database_dir):
self.database_dir = database_dir
def add(self, section, name, value):
# Where are we going to store the database file.
path_obj = path.path()
path_obj.fromstr(self.database_dir)
path_obj.add(section)
path_obj.add(name)
# The database file itself.
entry = path.path()
entry.fromstr(path_obj.tostr())
entry.add("data")
# Make the directoies.
os.makedirs(path_obj.tostr(), exist_ok = True)
# And write the value.
with open(entry.tostr(), 'w') as file:
file.write(value)
def get(self, section, name, value):
# Where are we going to store the database file.
path_obj = path.path()
path_obj.fromstr(self.database_dir)
path_obj.add(section)
path_obj.add(name)
# The database file itself.
entry = path.path()
entry.fromstr(path_obj.tostr())
entry.add("data")
# Return the data.
with open(entry.tostr(), 'r') as file:
return file.read()