-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from Wolfmyths/future-update
1.5.0
- Loading branch information
Showing
46 changed files
with
1,237 additions
and
558 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
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,28 @@ | ||
import json | ||
import logging | ||
import os | ||
|
||
class JSONParser(): | ||
file: dict[str:list[str]] = None | ||
def __init__(self, path: str, default: dict = {}) -> None: | ||
self.path = path | ||
self.default = default | ||
try: | ||
self.loadJSON() | ||
except (json.decoder.JSONDecodeError, FileNotFoundError): | ||
with open(self.path, 'w') as f: | ||
f.write(json.dumps(default)) | ||
|
||
self.loadJSON() | ||
|
||
def loadJSON(self): | ||
with open(self.path, 'r') as f: | ||
self.file = json.loads(f.read()) | ||
|
||
def saveJSON(self): | ||
with open(self.path, 'w') as f: | ||
f.seek(0) | ||
f.write(json.dumps(self.file, indent=2)) | ||
f.truncate() | ||
|
||
logging.info('%s has been saved.', os.path.basename(self.path)) |
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
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
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
Oops, something went wrong.