From acdc94cd06ef2b06daef941d3b5b120a9603a5d5 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sat, 18 Jan 2025 12:35:11 -0800 Subject: [PATCH] Create qrz.py --- modules/qrz.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 modules/qrz.py diff --git a/modules/qrz.py b/modules/qrz.py new file mode 100644 index 0000000..b4d4d0f --- /dev/null +++ b/modules/qrz.py @@ -0,0 +1,40 @@ +# Module to respomnd to new nodes we havent seen before with a hello message +# K7MHI Kelly Keeton 2024 + +import sqlite3 +from modules.log import * + +def initalize_qrz_database(): + # create the database + conn = sqlite3.connect('data/qrz.db') + c = conn.cursor() + # Check if the qrz table exists, and create it if it doesn't + c.execute('''CREATE TABLE IF NOT EXISTS qrz + (qrz_id INTEGER PRIMARY KEY, qrz_call TEXT, qrz_name TEXT, qrz_qth TEXT, qrz_notes TEXT)''') + conn.commit() + conn.close() + logger.debug("System: Ensured data/qrz.db exists with required tables") + +def never_seen_before(nodeID): + # check if we have seen this node before and sent a hello message + conn = sqlite3.connect('data/qrz.db') + c = conn.cursor() + c.execute("SELECT * FROM qrz WHERE qrz_call = ?", (nodeID,)) + row = c.fetchone() + conn.close() + if row is None: + return True + else: + return False + +def hello(nodeID, name, qth, notes): + # send a hello message + conn = sqlite3.connect('data/qrz.db') + c = conn.cursor() + c.execute("INSERT INTO qrz (qrz_call, qrz_name, qrz_qth, qrz_notes) VALUES (?, ?, ?, ?)", (nodeID, name, qth, notes)) + conn.commit() + conn.close() + return True + + +