I'm trying to get my code to store messages within txt file using json. Each time a new message comes in, it will add the new message to the array.
The structure will be:
{
"Messages": {
"Test Contact 2": {
"0": "\"Message 1"
},
"Test Contact 1": {
"0": "\"Message 1\"",
"1": "\"Message 2\""
}
}
}
And here is my current code:
class PluginOne(IPlugin):
def process(self):
try:
print("Database")
data_store('Test contact', 'Text Message')
pass
except Exception as exc:
print("Error in database: " + exc.args)
def data_store(key_id, key_info):
try:
with open('Plugins/Database/messages.txt', 'r+') as f:
data = json.load(f)
data[key_id] = key_info
f.seek(0)
json.dump(data, f)
f.truncate()
pass
except Exception as exc:
print("Error in data store: " + exc.args)
when I try to run the code, I get the following error
Can't convert 'tuple' object to str implicitly