From cb9af0f5b833d79a00aa4707355b3a92ff574a57 Mon Sep 17 00:00:00 2001 From: W1CDN Date: Sat, 13 May 2023 17:26:38 -0500 Subject: [PATCH] Move tuple of frame table fields to a separate files in case we need it more places. --- api_app.py | 50 ++------------------------------------------------ constants.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ kiss_and_db.py | 48 ------------------------------------------------ 3 files changed, 50 insertions(+), 96 deletions(-) create mode 100644 constants.py diff --git a/api_app.py b/api_app.py index 6ed1429..18054e3 100644 --- a/api_app.py +++ b/api_app.py @@ -11,53 +11,7 @@ api_app = Flask(__name__) api = Api(api_app) # TODO this is duplicated from kiss_and_db.py, can I avoid that? -db_fields = ("id", -"addresse", -"alive", -"altitude", -"comment", -"course", -"created", -"format", -"frame", -"from", -"gpsfixstatus", -"latitude", -"longitude", -"mbits", -"messagecapable", -"message_text", -"msgNo", -"mtype", -"object_format", -"object_name", -"path", -"phg", -"phg_dir", -"phg_gain", -"phg_height", -"phg_power", -"phg_range", -"posambiguity", -"raw", -"raw_timestamp", -"speed", -"station_call", -"station_lat", -"station_lon", -"status", -"subpacket", -"symbol", -"symbol_table", -"telemetry", -"timestamp", -"to", -"tEQNS", -"tPARM", -"tUNIT", -"via", -"weather", -"wx_raw_timestamp") +import constants def read_config(): config = configparser.ConfigParser() @@ -121,7 +75,7 @@ def select_frames(conn, n, from_, url_params): # Filter out any keys that don't match db fields # From https://stackoverflow.com/a/20256491 dictfilt = lambda x, y: dict([ (i,x[i]) for i in x if i in set(y) ]) - field_where = dictfilt(url_params, db_fields) + field_where = dictfilt(url_params, constants.db_frames_fields) # Then loop through fields to create query parts # From https://stackoverflow.com/a/73512269/2152245 field_where_str = ' AND '.join([f'"{k}" LIKE \'{v}\'' for k,v in field_where.items()]) diff --git a/constants.py b/constants.py new file mode 100644 index 0000000..3bd8420 --- /dev/null +++ b/constants.py @@ -0,0 +1,48 @@ +# Tuple of frames table fields +db_frames_fields = ("id", +"addresse", +"alive", +"altitude", +"comment", +"course", +"created", +"format", +"frame", +"from", +"gpsfixstatus", +"latitude", +"longitude", +"mbits", +"messagecapable", +"message_text", +"msgNo", +"mtype", +"object_format", +"object_name", +"path", +"phg", +"phg_dir", +"phg_gain", +"phg_height", +"phg_power", +"phg_range", +"posambiguity", +"raw", +"raw_timestamp", +"speed", +"station_call", +"station_lat", +"station_lon", +"status", +"subpacket", +"symbol", +"symbol_table", +"telemetry", +"timestamp", +"to", +"tEQNS", +"tPARM", +"tUNIT", +"via", +"weather", +"wx_raw_timestamp") diff --git a/kiss_and_db.py b/kiss_and_db.py index 24e4209..5e23ef9 100644 --- a/kiss_and_db.py +++ b/kiss_and_db.py @@ -6,54 +6,6 @@ import json import aprslib import configparser -db_fields = ("id", -"addresse", -"alive", -"altitude", -"comment", -"course", -"created", -"format", -"frame", -"from", -"gpsfixstatus", -"latitude", -"longitude", -"mbits", -"messagecapable", -"message_text", -"msgNo", -"mtype", -"object_format", -"object_name", -"path", -"phg", -"phg_dir", -"phg_gain", -"phg_height", -"phg_power", -"phg_range", -"posambiguity", -"raw", -"raw_timestamp", -"speed", -"station_call", -"station_lat", -"station_lon", -"status", -"subpacket", -"symbol", -"symbol_table", -"telemetry", -"timestamp", -"to", -"tEQNS", -"tPARM", -"tUNIT", -"via", -"weather", -"wx_raw_timestamp") - def read_config(): config = configparser.ConfigParser() config.read('config.ini')