diff --git a/functions.py b/functions.py index 5b8b1e7..7b8fff7 100644 --- a/functions.py +++ b/functions.py @@ -30,6 +30,25 @@ def saveJSON(dict, file_path): # dump the contents json.dump(dict, file, indent=4) +# append to a json file +def appendToJSON(new_data, file_path): + try: + # open the file + path = Path(file_path) + if not path.is_file(): + with open(path, 'w', encoding="utf-8") as file: + json.dump([], file) + + with open(path, 'r+', encoding="utf-8") as file: + file_data = json.load(file) + file_data.append(new_data) + file.seek(0) + json.dump(file_data, file, indent=4) + return True + except Exception as e: + app.logger.error(str(e)) + return False + cfg = loadJSON(const.configFile) def formatRelativeTime(date_str):