mirror of
https://codeberg.org/catask-org/catask.git
synced 2025-04-19 21:33:41 -05:00
add appendToJSON() function
This commit is contained in:
parent
30f90da265
commit
bbe8994907
1 changed files with 19 additions and 0 deletions
19
functions.py
19
functions.py
|
@ -30,6 +30,25 @@ def saveJSON(dict, file_path):
|
||||||
# dump the contents
|
# dump the contents
|
||||||
json.dump(dict, file, indent=4)
|
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)
|
cfg = loadJSON(const.configFile)
|
||||||
|
|
||||||
def formatRelativeTime(date_str):
|
def formatRelativeTime(date_str):
|
||||||
|
|
Loading…
Add table
Reference in a new issue