fixed some database bugs

This commit is contained in:
pdxlocations
2025-01-11 17:09:33 -08:00
parent 527aff0608
commit 037877180e
4 changed files with 14 additions and 8 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
.venv/
__pycache__/
client.db
.DS_Store

View File

@@ -53,7 +53,7 @@ def save_message_to_db(channel, user_id, message_text):
# Construct the table name
table_name = f"{str(get_nodeNum())}_{channel}_messages"
quoted_table_name = f'"{table_name}"' # Quote the table name becuase we might begin with numerics
quoted_table_name = f'"{table_name}"' # Quote the table name becuase we begin with numerics
# Ensure the table exists
create_table_query = f'''

View File

@@ -60,7 +60,7 @@ def on_receive(packet):
draw_channel_list()
update_messages_window()
save_message_to_db(globals.channel_list[channel_number], message_from_id, message_string)
save_message_to_db(node['num'], message_from_id, message_string)
except KeyError as e:
print(f"Error processing packet: {e}")

View File

@@ -3,14 +3,17 @@ from meshtastic.protobuf import config_pb2
import re
def get_channels():
"""Retrieve channels from the node and update globals.channel_list and globals.all_messages."""
node = globals.interface.getNode('^local')
device_channels = node.channels
channel_output = []
# Clear and rebuild channel list
globals.channel_list = []
for device_channel in device_channels:
if device_channel.role:
# Use the channel name if available, otherwise use the modem preset
if device_channel.settings.name:
# Use the channel name
channel_name = device_channel.settings.name
else:
# If channel name is blank, use the modem preset
@@ -19,14 +22,16 @@ def get_channels():
modem_preset_string = config_pb2._CONFIG_LORACONFIG_MODEMPRESET.values_by_number[modem_preset_enum].name
channel_name = convert_to_camel_case(modem_preset_string)
# Add channel to output
channel_output.append(channel_name)
# Add channel to globals.channel_list if not already present
if channel_name not in globals.channel_list:
globals.channel_list.append(channel_name)
# Only initialize globals.all_messages[channel_name] if it doesn't already exist
# Initialize globals.all_messages[channel_name] if it doesn't exist
if channel_name not in globals.all_messages:
globals.all_messages[channel_name] = []
return list(globals.all_messages.keys())
return globals.channel_list
def get_node_list():
node_list = []