-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made all options remember the last set value. Fixed app crashing when no path was input.
- Loading branch information
1 parent
e242a18
commit 51f00ec
Showing
2 changed files
with
88 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import json | ||
import os | ||
|
||
|
||
class SaveHandler: | ||
def __init__(self, file: str = "save_data.json"): | ||
self.file = file | ||
if not os.path.exists(self.file): | ||
with open(self.file, 'w') as file: | ||
print("test") | ||
json.dump({}, file) | ||
|
||
def has_save(self, key: str) -> bool: | ||
with open(self.file, 'r') as file: | ||
if key in json.load(file): | ||
return True | ||
else: | ||
return False | ||
|
||
def get_save(self, key: str) -> str: | ||
with open(self.file, 'r') as file: | ||
return json.load(file)[key] | ||
|
||
def set_save(self, key: str, value: str): | ||
with open(self.file, 'r') as file: | ||
data = json.load(file) | ||
data[key] = value | ||
with open(self.file, 'w') as file: | ||
json.dump(data, file) | ||
|
||
def delete_save(self, key: str): | ||
with open(self.file, 'r') as file: | ||
data = json.load(file) | ||
data.pop(key, None) | ||
with open(self.file, 'w') as file: | ||
json.dump(data, file) |