make mailbox file persistent

This commit is contained in:
KF7EEL 2021-03-02 13:43:15 -08:00
parent 6153f7da1c
commit b22cfdbab4
3 changed files with 16 additions and 16 deletions

View File

@ -185,21 +185,21 @@ def dashboard_bb_write(call, dmr_id, time, bulletin):
#logger.info(dash_bb)
def mailbox_write(call, dmr_id, time, message, recipient):
#try:
mail_file = ast.literal_eval(os.popen('cat /tmp/gps_data_user_mailbox.txt').read())
mail_file = ast.literal_eval(os.popen('cat ./gps_data_user_mailbox.txt').read())
mail_file.insert(0, {'call': call, 'dmr_id': dmr_id, 'time': time, 'message':message, 'recipient': recipient})
with open("/tmp/gps_data_user_mailbox.txt", 'w') as mailbox_file:
with open("./gps_data_user_mailbox.txt", 'w') as mailbox_file:
mailbox_file.write(str(mail_file[:100]))
mailbox_file.close()
logger.info('User mail saved.')
def mailbox_delete(dmr_id):
mail_file = ast.literal_eval(os.popen('cat /tmp/gps_data_user_mailbox.txt').read())
mail_file = ast.literal_eval(os.popen('cat ./gps_data_user_mailbox.txt').read())
call = str(get_alias((dmr_id), subscriber_ids))
new_data = []
for message in mail_file:
if message['recipient'] != call:
new_data.append(message)
with open("/tmp/gps_data_user_mailbox.txt", 'w') as mailbox_file:
with open("./gps_data_user_mailbox.txt", 'w') as mailbox_file:
mailbox_file.write(str(new_data[:100]))
mailbox_file.close()
logger.info('Mailbox updated. Delete occurred.')
@ -1788,11 +1788,11 @@ if __name__ == '__main__':
with open("/tmp/gps_data_user_bb.txt", 'w') as user_bb_file:
user_bb_file.write("[]")
user_bb_file.close()
if Path('/tmp/gps_data_user_mailbox.txt').is_file():
if Path('./gps_data_user_mailbox.txt').is_file():
pass
else:
Path('/tmp/gps_data_user_mailbox.txt').touch()
with open("/tmp/gps_data_user_mailbox.txt", 'w') as user_loc_file:
Path('./gps_data_user_mailbox.txt').touch()
with open("./gps_data_user_mailbox.txt", 'w') as user_loc_file:
user_loc_file.write("[]")
user_loc_file.close()

View File

@ -179,21 +179,21 @@ def dashboard_bb_write(call, dmr_id, time, bulletin):
def mailbox_write(call, dmr_id, time, message, recipient):
#try:
mail_file = ast.literal_eval(os.popen('cat /tmp/gps_data_user_mailbox.txt').read())
mail_file = ast.literal_eval(os.popen('cat ./gps_data_user_mailbox.txt').read())
mail_file.insert(0, {'call': call, 'dmr_id': dmr_id, 'time': time, 'message':message, 'recipient': recipient})
with open("/tmp/gps_data_user_mailbox.txt", 'w') as mailbox_file:
with open("./gps_data_user_mailbox.txt", 'w') as mailbox_file:
mailbox_file.write(str(mail_file[:100]))
mailbox_file.close()
logger.info('User mail saved.')
def mailbox_delete(dmr_id):
mail_file = ast.literal_eval(os.popen('cat /tmp/gps_data_user_mailbox.txt').read())
mail_file = ast.literal_eval(os.popen('cat ./gps_data_user_mailbox.txt').read())
call = str(get_alias((dmr_id), subscriber_ids))
new_data = []
for message in mail_file:
if message['recipient'] != call:
new_data.append(message)
with open("/tmp/gps_data_user_mailbox.txt", 'w') as mailbox_file:
with open("./gps_data_user_mailbox.txt", 'w') as mailbox_file:
mailbox_file.write(str(new_data[:100]))
mailbox_file.close()
logger.info('Mailbox updated. Delete occurred.')
@ -694,11 +694,11 @@ if __name__ == '__main__':
with open("/tmp/gps_data_user_bb.txt", 'w') as user_bb_file:
user_bb_file.write("[]")
user_bb_file.close()
if Path('/tmp/gps_data_user_mailbox.txt').is_file():
if Path('./gps_data_user_mailbox.txt').is_file():
pass
else:
Path('/tmp/gps_data_user_mailbox.txt').touch()
with open("/tmp/gps_data_user_mailbox.txt", 'w') as user_loc_file:
Path('./gps_data_user_mailbox.txt').touch()
with open("./gps_data_user_mailbox.txt", 'w') as user_loc_file:
user_loc_file.write("[]")
user_loc_file.close()
# CLI argument parser - handles picking up the config file from the command line, and sending a "help" message

View File

@ -471,7 +471,7 @@ def mailbox():
"""
else:
mailbox_file = ast.literal_eval(os.popen('cat /tmp/gps_data_user_mailbox.txt').read())
mailbox_file = ast.literal_eval(os.popen('cat ../../gps_data_user_mailbox.txt').read())
mail_content = '<h2 style="text-align: center;">Messages for: ' + recipient.upper() + '''
</h2>\n<p style="text-align: center;"><button onclick="history.back()">Back</button></p>\n
<h4 style="text-align: center;"><a href="mailbox_rss?recipient=''' + recipient.upper() + '''"><em>Mailbox RSS Feed for ''' + recipient.upper() + '''</em></a><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH5QIcFBAOXAevLAAAAZZJREFUSMftlbtKA0EUhj8jWhi8gaIEC29oxEoRFESLgIXYiWVSKoj6CCrBBwj6CBHNE1hEWy21ETQqiIW1wXhPo81ZOBw2apbdVPvDsDPnP8M/5zKzECJEQKivYO8DFoAYEAGKtTpQEvhW4w3IA+tAVy2F9fgEskA8COHUL8LOKAMZoMmLQF0FewcwImmNAzPANBB18b0BFoGroNLfBiyLgI2+BMwF3XgNwCrwYsQ//BBPSRPdAoeybjE+A8ClS+Sjfnf1E5A2dW4FzoxfwWvD/XWd7oAxI24jz3gVnpS7eiEpt+KvQEL5D5qal/245zFgU+pnXzMd+Zrh9/3q5l7g3CXtTs0bgWvFffn5vDa7iKcVv2K4DS8i3cAOsAuMm8h12ovqqrVL/R3upFrRKPBgHgctvm0iSynuWNnf5bf6byy5dPKe4nukhg6XU9yW2TfsJlDpNCUX27OaP8pD4WBCzQtmX381EUeAI3Xqe6m5xoHpYAezJuJkNb9Fh0tI4+SlXhpTwJBaZ+XbCcwr+6kcPESI2uAHmAijFaMnEmYAAAAASUVORK5CYII=" /></h4>
@ -537,7 +537,7 @@ def bb_rss():
@app.route('/mailbox_rss')
def mail_rss():
mailbox_file = ast.literal_eval(os.popen('cat /tmp/gps_data_user_mailbox.txt').read())
mailbox_file = ast.literal_eval(os.popen('cat ./gps_data_user_mailbox.txt').read())
post_data = ''
recipient = request.args.get('recipient').upper()
rss_header = """<?xml version="1.0" encoding="UTF-8" ?>