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')