Skip to content

Commit

Permalink
Remove some repeat blocs
Browse files Browse the repository at this point in the history
  • Loading branch information
sunwaterdev committed Jul 11, 2024
1 parent 475ea99 commit 1ba3f87
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions lidya/libs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,21 @@ def get_messages(self):
return self.messages

def rewirte_config(self):
"""Rewirte the entire configuration"""
wakewords_file = self.config_folder + "/wakewords.json"
config_file = self.config_folder + "/config.json"
keys_file = self.config_folder + "/keys.json"
messages_file = self.config_folder + "/messages.json"

with open(wakewords_file, "a", encoding="utf-8") as file:
file.write(json.dumps(self.wakewords))

with open(config_file, "a", encoding="utf-8") as file:
file.write(json.dumps(self.config))

with open(keys_file, "a", encoding="utf-8") as file:
file.write(json.dumps(self.keys))

with open(messages_file, "a", encoding="utf-8") as file:
file.write(json.dumps(self.messages))
"""Rewirte every configuration"""
files = {
"wakewords_file": self.config_folder + "/wakewords.json",
"config_file": self.config_folder + "/config.json",
"keys_file": self.config_folder + "/keys.json",
"messages_file": self.config_folder + "/messages.json"
}

for key, value in files.items():
with open(value, "a", encoding="utf-8") as file:
if key == "wakewords_file":
file.write(json.dumps(self.wakewords))
elif key == "config_file":
file.write(json.dumps(self.config))
elif key == "keys_file":
file.write(json.dumps(self.keys))
elif key == "messages_file":
file.write(json.dumps(self.messages))

0 comments on commit 1ba3f87

Please sign in to comment.