From 4ef11f229358a8fda39d84c2638d5a5f2fde74f1 Mon Sep 17 00:00:00 2001 From: Michael Clemens Date: Thu, 20 May 2021 23:36:19 +0200 Subject: [PATCH] added inline documentation moved default values into the config file --- config.ini.dist | 7 +++++++ qrzlogger.py | 35 ++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/config.ini.dist b/config.ini.dist index 538b2e9..b5bd09b 100644 --- a/config.ini.dist +++ b/config.ini.dist @@ -5,3 +5,10 @@ api_key = 1234-ABCD-1234-A1B2 qrz_user = N0CALL qrz_pass = q1w2e3r4t5z6u7i8o9 xml_fields = ("call", "band", "mode", "qso_date", "time_on", "rst_sent", "rst_rcvd", "comment") + +# default values for new QSOs +band = "40m" +mode = "SSB" +rst_rcvd = "59" +rst_sent = "59" +tx_pwr = "5" diff --git a/qrzlogger.py b/qrzlogger.py index 4de6f1f..61fb486 100644 --- a/qrzlogger.py +++ b/qrzlogger.py @@ -53,10 +53,11 @@ from datetime import date from datetime import timezone import configparser -# read in the config +# read the config file config = configparser.ConfigParser() config.read('config.ini') +# headers for all POST requests headers = CaseInsensitiveDict() headers["Content-Type"] = "application/x-www-form-urlencoded" @@ -107,12 +108,14 @@ def getCallData(call): # Query QRZ.com's logbook for all previous QSOs # with a specific call sign def getQSOsForCallsign(callsign): - option = "TYPE:ADIF,CALL:"+callsign - fetch = { 'KEY' : config['qrzlogger']['api_key'], 'ACTION' : 'FETCH', 'OPTION' : option} - data = urllib.parse.urlencode(fetch) + post_data = { + 'KEY' : config['qrzlogger']['api_key'], + 'ACTION' : 'FETCH', + 'OPTION' : "TYPE:ADIF,CALL:" + callsign + } + post_data_enc = urllib.parse.urlencode(post_data) - resp = requests.post(config['qrzlogger']['api_url'], headers=headers, data=data) - #resp = requests.post(config['qrzlogger']['api_url'], data=fetch) + resp = requests.post(config['qrzlogger']['api_url'], headers=headers, data=post_data_enc) str_resp = resp.content.decode("utf-8") response = urllib.parse.unquote(str_resp) @@ -194,15 +197,19 @@ def queryQSOData(qso): dt = datetime.datetime.now(timezone.utc) dt_now = dt.replace(tzinfo=timezone.utc) + # pre-fill the fields with date, time and + # default values from the config file qso_date = dt_now.strftime("%Y%m%d") time_on = dt_now.strftime("%H%M") - band = "40m" - mode = "SSB" - rst_rcvd = "59" - rst_sent = "59" - tx_pwr = "100" + band = config['qrzlogger']['band'] + mode = config['qrzlogger']['mode'] + rst_rcvd = config['qrzlogger']['rst_rcvd'] + rst_sent = config['qrzlogger']['rst_sent'] + tx_pwr = config['qrzlogger']['tx_pwr'] comment = "" + # If this is the first try filling out the QSO fields + # then we use defaults if qso is None: questions = { "qso_date" : ["QSO Date: ",qso_date], @@ -214,11 +221,17 @@ def queryQSOData(qso): "tx_pwr": ["Power (in W): ", tx_pwr], "comment": ["Comment: ", comment] } + # if this is not the first try, we pre-fill the + # vaulues we got from the last try else: questions = qso + # We now loop through all defined fields and ask + # the user for input for q in questions: inp = input(questions[q][0]+" ["+questions[q][1]+"]: " ) + # If the user just hits enter, we keep the default value. + # If not, we keep the data provided by the user if inp != "": questions[q][1] = inp