-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSecret.py
More file actions
26 lines (20 loc) · 725 Bytes
/
Secret.py
File metadata and controls
26 lines (20 loc) · 725 Bytes
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
import json
import os
class Secret:
def __init__(self) -> None:
if not os.path.exists('secret.json'):
with open('secret.json', 'w') as f:
json.dump({"token": "", "chat_id": ""}, f)
with open('secret.json', 'r') as f:
__secret = json.load(f)
self.__secret = __secret
def __getitem__(self, key):
if key not in self.__secret:
raise KeyError(f"{key} not found in secret.json")
return self.__secret[key]
def __setitem__(self, key, value):
self.__secret[key] = value
with open('secret.json', 'w') as f:
json.dump(self.__secret, f)
def toJSON(self):
return self.__secret