Added Message Board pruning

* Script will now prune the message board to 'max_messages' to ensure the board doesn't get too long, default set to 20
* adjusted indents to match in all functions
This commit is contained in:
chengtripp 2023-02-01 10:29:58 +00:00 committed by GitHub
parent c343ac170a
commit 6b9418a917
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,11 +9,11 @@ display_name = "SolarExpress Message Board"
configdir = os.getcwd() configdir = os.getcwd()
identitypath = configdir+"/storage/identity" identitypath = configdir+"/storage/identity"
redis_db = 2 redis_db = 2
max_messages = 20
r = redis.Redis(db=redis_db, decode_responses=True) r = redis.Redis(db=redis_db, decode_responses=True)
def setup_lxmf(): def setup_lxmf():
if os.path.isfile(identitypath): if os.path.isfile(identitypath):
identity = RNS.Identity.from_file(identitypath) identity = RNS.Identity.from_file(identitypath)
RNS.log('Loaded identity from file', RNS.LOG_INFO) RNS.log('Loaded identity from file', RNS.LOG_INFO)
@ -104,6 +104,9 @@ def announce_check():
announce_now(local_lxmf_destination) announce_now(local_lxmf_destination)
RNS.log('Announcement sent, expr set 1800 seconds', RNS.LOG_INFO) RNS.log('Announcement sent, expr set 1800 seconds', RNS.LOG_INFO)
def prune_messageboard(max_messages):
RNS.log('Pruning message board', RNS.LOG_DEBUG)
r.ltrim('message_board_general', 0, max_messages -1)
# Start Reticulum and print out all the debug messages # Start Reticulum and print out all the debug messages
reticulum = RNS.Reticulum(loglevel=RNS.LOG_VERBOSE) reticulum = RNS.Reticulum(loglevel=RNS.LOG_VERBOSE)
@ -142,5 +145,8 @@ while True:
# Check whether we need to make another announcement # Check whether we need to make another announcement
announce_check() announce_check()
# Keep the message board trim
prune_messageboard(max_messages)
#Sleep #Sleep
time.sleep(10) time.sleep(10)