Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Jun 9, 2025. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
Latest commit
54 lines (44 loc) · 1.46 KB
/
Copy pathdb.py
File metadata and controls
54 lines (44 loc) · 1.46 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
""" DB """
importbase64
importbinascii
fromastimportliteral_eval
db_path='db/db'
defenc(text):
""" Encode the given text to base64 """
# https://www.scopulus.co.uk/tools/hexconverter.htm
# convert to BASE64
b64_bytes=base64.b64encode(text.encode('ascii'))
# convert to HEX-ASCII and return the result
returnbinascii.hexlify(b64_bytes.decode('ascii').encode())
defdec(text):
""" Encode the given text to base64 """
hex_bytes=bytearray.fromhex(text).decode()
returnbase64.b64decode(hex_bytes).decode()
defread_file(path):
""" Read and return the file text """
withopen(path, encoding='utf8') asfile:
returnfile.read()
defwrite_file(path, text):
""" Write text to the given file """
withopen(path, 'w', encoding='utf8') asfile:
returnfile.write(text)
defiskeyexist(key):
file=read_file(db_path)
data:dict=literal_eval(dec(file))
returnnotdata.get(key, False) ==False
defwrite(key, value):
file=read_file(db_path)
data:dict=literal_eval(dec(file))
data[key] =value
write_file(db_path, str(enc(str(data)))[2:-1])
defrem(key):
file=read_file(db_path)
data:dict=literal_eval(dec(file))
data.pop(key)
write_file(db_path, str(enc(str(data)))[2:-1])
defread(key):
data=literal_eval(dec(read_file(db_path)))
write_file(db_path, str(enc(str(data)))[2:-1])
returndata[key]
defiskeyindict(dic, key):
returnkeyindic.keys()