How to add a command for discord py to to backup a JSON file and save as duplicate name.
Example: If i have amounts.json file in same directory of bot.py.
i want it to create a back up with duplicate number while it saves everytime.
How to add a command for discord py to to backup a JSON file and save as duplicate name.
Example: If i have amounts.json file in same directory of bot.py.
i want it to create a back up with duplicate number while it saves everytime.
I'm not sure what your needs are. If you want to save the current amounts to amounts.json file and overwrite it every time, your code in the question would suffice.
If you want to save the amounts to a different file so that you can say look back and see the contents of amounts at a some previous time, you can add timestamp to your file by
(assuming you had imported datetime by from datetime import datetime
def _save_with_timestamp():
with open('amounts-{}.json'.format(datetime.now().strftime('%Y-%m-%d-%X')), 'w+') as f:
json.dump(amounts, f)
Say, at 2018-11-29-19:00:01 you pressed save and then the contents of amounts might be saved to a json file named amounts-2018-11-29-19:00:02.json.