2021-05-20 12:05:33 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
# qrzlogger
|
|
|
|
# =========
|
|
|
|
#
|
|
|
|
# This script is a QRZ.com command line QSO logger.
|
|
|
|
# It does the following:
|
|
|
|
# 1) asks the user for a call sign
|
|
|
|
# 2) displays available call sign info pulled from QRZ.com
|
|
|
|
# 3) displays all previous QSOs with this call (pulled from QRZ.com logbook)
|
|
|
|
# 4) alles the user to enter QSO specific data (date, time, report, band etc.)
|
|
|
|
# 5) uploads the QSO to QRZ.com's logbook
|
|
|
|
# 6) lists the last 5 logged QSOs ((pulled from QRZ.com logbook)
|
|
|
|
# 7) starts again from 1)
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# MIT License
|
|
|
|
#
|
|
|
|
# Copyright (c) 2021 Michael Clemens, DL6MHC
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in all
|
|
|
|
# copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
# WARNING: This software is beta and is really not working properly yet!
|
|
|
|
# I'll remove this warning when it's done
|
|
|
|
|
|
|
|
|
|
|
|
import requests
|
|
|
|
import urllib
|
|
|
|
import re
|
|
|
|
import datetime
|
|
|
|
import os
|
|
|
|
import xmltodict
|
|
|
|
from prettytable import PrettyTable
|
|
|
|
from requests.structures import CaseInsensitiveDict
|
|
|
|
from datetime import date
|
|
|
|
from datetime import timezone
|
|
|
|
import configparser
|
2021-05-21 10:20:34 -04:00
|
|
|
from colored import fore, back, style
|
2021-05-20 12:05:33 -04:00
|
|
|
|
2021-05-20 17:36:19 -04:00
|
|
|
# read the config file
|
2021-05-20 12:05:33 -04:00
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config.read('config.ini')
|
|
|
|
|
2021-05-20 17:36:19 -04:00
|
|
|
# headers for all POST requests
|
2021-05-20 12:05:33 -04:00
|
|
|
headers = CaseInsensitiveDict()
|
|
|
|
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
|
|
|
|
|
|
|
session = None
|
|
|
|
session_key = None
|
|
|
|
|
2021-05-21 10:20:34 -04:00
|
|
|
# Read user definable colors from config
|
|
|
|
if config['qrzlogger']['use_colors'] == "yes":
|
|
|
|
inputcol = eval(config['qrzlogger']['inputcol'])
|
|
|
|
hlcol = eval(config['qrzlogger']['hlcol'])
|
|
|
|
defvalcol = eval(config['qrzlogger']['defvalcol'])
|
|
|
|
errorcol = eval(config['qrzlogger']['errorcol'])
|
|
|
|
successcol = eval(config['qrzlogger']['successcol'])
|
|
|
|
tablecol = eval(config['qrzlogger']['tablecol'])
|
|
|
|
logocol = eval(config['qrzlogger']['logocol'])
|
|
|
|
else:
|
|
|
|
inputcol = style.RESET
|
|
|
|
hlcol = style.RESET
|
|
|
|
defvalcol = style.RESET
|
|
|
|
errorcol = style.RESET
|
|
|
|
successcol = style.RESET
|
|
|
|
tablecol = style.RESET
|
|
|
|
logocol = style.RESET
|
|
|
|
|
2021-05-21 18:05:23 -04:00
|
|
|
bandfreqs = {
|
|
|
|
'160m' : '1.850',
|
|
|
|
'80m' : '3.700',
|
|
|
|
'60m' : '5.355',
|
|
|
|
'40m' : '7.100',
|
|
|
|
'30m' : '10.130',
|
|
|
|
'20m' : '14.200',
|
|
|
|
'17m' : '18.130',
|
|
|
|
'15m' : '21.200',
|
|
|
|
'12m' : '24.950',
|
|
|
|
'10m' : '28.500',
|
|
|
|
'6m' : '50.150',
|
|
|
|
'2m' : '145.500',
|
|
|
|
'70cm' : '432.300'
|
|
|
|
}
|
|
|
|
|
2021-05-20 12:05:33 -04:00
|
|
|
|
|
|
|
# Generate a session for QRZ.com's xml service with
|
|
|
|
# the help of the QRZ.com username and password
|
|
|
|
def get_session():
|
|
|
|
global session
|
|
|
|
global session_key
|
|
|
|
xml_auth_url = '''https://xmldata.QRZ.com/xml/current/?username={0}&password={1}'''.format(
|
|
|
|
config['qrzlogger']['qrz_user'],config['qrzlogger']['qrz_pass'])
|
2021-05-21 18:05:23 -04:00
|
|
|
try:
|
|
|
|
session = requests.Session()
|
|
|
|
session.verify = bool(os.getenv('SSL_VERIFY', True))
|
|
|
|
r = session.get(xml_auth_url)
|
|
|
|
if r.status_code == 200:
|
|
|
|
raw_session = xmltodict.parse(r.content)
|
|
|
|
session_key = raw_session.get('QRZDatabase').get('Session').get('Key')
|
|
|
|
if session_key:
|
|
|
|
return True
|
2021-05-24 08:46:28 -04:00
|
|
|
except requests.exceptions.ConnectionError as e_conn:
|
|
|
|
print(errorcol + "\nUnable to connect to xmldata.qrz.com:")
|
|
|
|
print(e_conn)
|
|
|
|
print("\nPlease check if\n * username and password are correct (see config.ini)\n * you are connected to the internet")
|
|
|
|
print(style.RESET)
|
2021-05-21 18:05:23 -04:00
|
|
|
except:
|
2021-05-24 08:46:28 -04:00
|
|
|
print(errorcol + "\nsomething unexpected has happened:\n")
|
|
|
|
print(e_conn)
|
|
|
|
print(style.RESET)
|
2021-05-20 12:05:33 -04:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
2021-05-24 08:46:28 -04:00
|
|
|
# Sends a POST request to QRZ.com, checks for errors
|
|
|
|
# and returns teh response
|
|
|
|
def sendRequest(post_data):
|
|
|
|
try:
|
|
|
|
resp = requests.post(config['qrzlogger']['api_url'], headers=headers, data=post_data)
|
|
|
|
if resp.status_code == 200:
|
|
|
|
str_resp = resp.content.decode("utf-8")
|
|
|
|
response = urllib.parse.unquote(str_resp)
|
|
|
|
resp_list = response.splitlines()
|
|
|
|
if resp_list[0]:
|
|
|
|
if "invalid api key" in resp_list[0]:
|
|
|
|
print(errorcol + "\nThe API key configured in config.ini is not correct.\n" + style.RESET)
|
|
|
|
else:
|
|
|
|
return response
|
|
|
|
elif resp.status_code == 404:
|
|
|
|
print(errorcol + "\nThe API URL could not be found. Please check the URL in config.ini\n" + style.RESET)
|
|
|
|
except requests.exceptions.ConnectionError as e_conn:
|
|
|
|
print(errorcol + "\nUnable to connect to xmldata.qrz.com:")
|
|
|
|
print(e_conn)
|
|
|
|
print("\nPlease check if you are connected to the internet")
|
|
|
|
print(style.RESET)
|
|
|
|
except:
|
|
|
|
print(errorcol + "\nsomething unexpected has happened:\n")
|
|
|
|
print(e_conn)
|
|
|
|
print(style.RESET)
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2021-05-20 12:05:33 -04:00
|
|
|
# Query QRZ.com's xml api to gather information
|
|
|
|
# about a specific call sign
|
|
|
|
def getCallData(call):
|
|
|
|
global session
|
|
|
|
global session_key
|
|
|
|
|
2021-05-24 08:46:28 -04:00
|
|
|
try:
|
|
|
|
xml_url = """https://xmldata.QRZ.com/xml/current/?s={0}&callsign={1}""" .format(session_key, call)
|
|
|
|
r = session.get(xml_url)
|
|
|
|
raw = xmltodict.parse(r.content).get('QRZDatabase')
|
|
|
|
calldata = raw.get('Callsign')
|
|
|
|
if calldata:
|
|
|
|
return calldata
|
|
|
|
except requests.exceptions.ConnectionError as e_conn:
|
|
|
|
print(errorcol + "\nUnable to connect to xmldata.qrz.com:")
|
|
|
|
print(e_conn)
|
|
|
|
print("\nPlease check if you are connected to the internet")
|
|
|
|
print(style.RESET)
|
|
|
|
except:
|
|
|
|
print(errorcol + "\nsomething unexpected has happened:\n")
|
|
|
|
print(e_conn)
|
|
|
|
print(style.RESET)
|
2021-05-21 12:12:46 -04:00
|
|
|
return None
|
2021-05-20 12:05:33 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Query QRZ.com's logbook for all previous QSOs
|
|
|
|
# with a specific call sign
|
|
|
|
def getQSOsForCallsign(callsign):
|
2021-05-20 17:36:19 -04:00
|
|
|
post_data = {
|
|
|
|
'KEY' : config['qrzlogger']['api_key'],
|
|
|
|
'ACTION' : 'FETCH',
|
|
|
|
'OPTION' : "TYPE:ADIF,CALL:" + callsign
|
|
|
|
}
|
2021-05-24 08:46:28 -04:00
|
|
|
post_data = urllib.parse.urlencode(post_data)
|
2021-05-20 12:05:33 -04:00
|
|
|
|
2021-05-24 08:46:28 -04:00
|
|
|
response = sendRequest(post_data)
|
2021-05-20 12:05:33 -04:00
|
|
|
|
2021-05-24 08:46:28 -04:00
|
|
|
if response:
|
|
|
|
resp_list = response.splitlines()
|
|
|
|
result = [{}]
|
|
|
|
for i in resp_list:
|
|
|
|
if not i:
|
|
|
|
result.append({})
|
|
|
|
else:
|
|
|
|
if any(s+":" in i for s in config['qrzlogger']['xml_fields']):
|
|
|
|
i = re.sub('<','',i, flags=re.DOTALL)
|
|
|
|
i = re.sub(':.*>',":",i, flags=re.DOTALL)
|
|
|
|
v = re.sub('^.*:',"",i, flags=re.DOTALL)
|
|
|
|
k = re.sub(':.*$',"",i, flags=re.DOTALL)
|
|
|
|
result[-1][k] = v
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
2021-05-20 12:05:33 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Generate a pretty ascii table containing all
|
|
|
|
# previous QSOs with a specific call sign
|
|
|
|
def getQSOTable(result):
|
|
|
|
t = PrettyTable(['Date', 'Time', 'Band', 'Mode', 'RST-S', 'RST-R', 'Comment'])
|
2021-05-22 17:16:32 -04:00
|
|
|
for qso in result:
|
|
|
|
if "qso_date" in qso:
|
|
|
|
date = datetime.datetime.strptime(qso["qso_date"], '%Y%m%d').strftime('%Y/%m/%d')
|
|
|
|
time = datetime.datetime.strptime(qso["time_on"], '%H%M').strftime('%H:%M')
|
|
|
|
# add missing fields to dict
|
|
|
|
for field in ["band", "mode", "rst_sent", "rst_rcvd", "comment"]:
|
|
|
|
if field not in qso:
|
|
|
|
qso[field] = ""
|
|
|
|
t.add_row([date, time, qso["band"], qso["mode"], qso["rst_sent"], qso["rst_rcvd"], qso["comment"]])
|
2021-05-20 12:05:33 -04:00
|
|
|
t.align = "r"
|
|
|
|
return t
|
|
|
|
|
2021-05-21 04:47:02 -04:00
|
|
|
|
2021-05-20 12:05:33 -04:00
|
|
|
# Print a pretty ascii table containing all interesting
|
|
|
|
# data found for a specific call sign
|
|
|
|
def getXMLQueryTable(result):
|
|
|
|
t = PrettyTable(['key', 'value'])
|
|
|
|
if "fname" in result:
|
|
|
|
t.add_row(["First Name", result["fname"]])
|
|
|
|
if "name" in result:
|
|
|
|
t.add_row(["Last Name", result["name"]])
|
|
|
|
if "addr1" in result:
|
|
|
|
t.add_row(["Street", result["addr1"]])
|
|
|
|
if "addr2" in result:
|
|
|
|
t.add_row(["City", result["addr2"]])
|
|
|
|
if "state" in result:
|
|
|
|
t.add_row(["State", result["state"]])
|
|
|
|
if "country" in result:
|
|
|
|
t.add_row(["Country", result["country"]])
|
|
|
|
if "grid" in result:
|
|
|
|
t.add_row(["Locator", result["grid"]])
|
|
|
|
if "email" in result:
|
|
|
|
t.add_row(["Email", result["email"]])
|
|
|
|
if "qslmgr" in result:
|
|
|
|
t.add_row(["QSL via:", result["qslmgr"]])
|
|
|
|
t.align = "l"
|
|
|
|
t.header = False
|
|
|
|
return t
|
|
|
|
|
|
|
|
|
|
|
|
# Print a pretty ascii table containing all
|
|
|
|
# previously entered user data
|
|
|
|
def getQSODetailTable(qso):
|
|
|
|
t = PrettyTable(['key', 'value'])
|
|
|
|
for q in qso:
|
|
|
|
t.add_row([qso[q][0], qso[q][1]])
|
|
|
|
t.align = "l"
|
|
|
|
t.header = False
|
|
|
|
return t
|
|
|
|
|
|
|
|
|
|
|
|
# Queries QSO specific data from the user via
|
|
|
|
# the command line
|
|
|
|
def queryQSOData(qso):
|
|
|
|
dt = datetime.datetime.now(timezone.utc)
|
|
|
|
dt_now = dt.replace(tzinfo=timezone.utc)
|
|
|
|
|
2021-05-20 17:36:19 -04:00
|
|
|
# pre-fill the fields with date, time and
|
|
|
|
# default values from the config file
|
2021-05-20 12:05:33 -04:00
|
|
|
qso_date = dt_now.strftime("%Y%m%d")
|
2021-05-20 15:44:59 -04:00
|
|
|
time_on = dt_now.strftime("%H%M")
|
2021-05-20 17:36:19 -04:00
|
|
|
band = config['qrzlogger']['band']
|
2021-05-21 18:05:23 -04:00
|
|
|
freq = ""
|
2021-05-20 17:36:19 -04:00
|
|
|
mode = config['qrzlogger']['mode']
|
|
|
|
rst_rcvd = config['qrzlogger']['rst_rcvd']
|
|
|
|
rst_sent = config['qrzlogger']['rst_sent']
|
|
|
|
tx_pwr = config['qrzlogger']['tx_pwr']
|
2021-05-20 12:05:33 -04:00
|
|
|
comment = ""
|
|
|
|
|
2021-05-20 17:36:19 -04:00
|
|
|
# If this is the first try filling out the QSO fields
|
|
|
|
# then we use defaults
|
2021-05-20 12:05:33 -04:00
|
|
|
if qso is None:
|
|
|
|
questions = {
|
2021-05-21 10:20:34 -04:00
|
|
|
"qso_date" : ["QSO Date",qso_date],
|
|
|
|
"time_on": ["QSO Time", time_on],
|
|
|
|
"band": ["Band", band],
|
2021-05-21 18:05:23 -04:00
|
|
|
"freq": ["Frequency", freq],
|
2021-05-21 10:20:34 -04:00
|
|
|
"mode": ["Mode", mode],
|
|
|
|
"rst_rcvd": ["RST Received", rst_rcvd],
|
|
|
|
"rst_sent": ["RST Sent", rst_sent],
|
|
|
|
"tx_pwr": ["Power (in W)", tx_pwr],
|
|
|
|
"comment": ["Comment", comment]
|
2021-05-20 12:05:33 -04:00
|
|
|
}
|
2021-05-20 17:36:19 -04:00
|
|
|
# if this is not the first try, we pre-fill the
|
|
|
|
# vaulues we got from the last try
|
2021-05-20 12:05:33 -04:00
|
|
|
else:
|
|
|
|
questions = qso
|
|
|
|
|
2021-05-20 17:36:19 -04:00
|
|
|
# We now loop through all defined fields and ask
|
|
|
|
# the user for input
|
2021-05-20 12:05:33 -04:00
|
|
|
for q in questions:
|
2021-05-21 10:20:34 -04:00
|
|
|
txt = inputcol + questions[q][0] + " [" + defvalcol + questions[q][1] + inputcol + "]:" + style.RESET
|
|
|
|
inp = input(txt)
|
2021-05-20 17:36:19 -04:00
|
|
|
# If the user just hits enter, we keep the default value.
|
|
|
|
# If not, we keep the data provided by the user
|
2021-05-21 17:36:05 -04:00
|
|
|
if inp == "c":
|
|
|
|
return None
|
2021-05-20 12:05:33 -04:00
|
|
|
if inp != "":
|
|
|
|
questions[q][1] = inp
|
2021-05-21 18:05:23 -04:00
|
|
|
# check if we are asking for the band
|
|
|
|
if q == "band":
|
|
|
|
# check if the band is in the bandfreqs dictionary
|
|
|
|
if questions[q][1] in bandfreqs:
|
|
|
|
# populate the frequency with a common freq of this band
|
|
|
|
questions['freq'][1] = bandfreqs[questions[q][1]]
|
2021-05-20 12:05:33 -04:00
|
|
|
return questions
|
|
|
|
|
|
|
|
|
|
|
|
# Sends the previously collected QSO information as a new
|
|
|
|
# QRZ.com logbook entry via the API
|
|
|
|
def sendQSO(qso):
|
2021-05-21 04:47:02 -04:00
|
|
|
is_ok = False
|
2021-05-20 15:37:43 -04:00
|
|
|
|
2021-05-20 16:55:40 -04:00
|
|
|
# construct ADIF QSO entry
|
|
|
|
adif = '<station_callsign:' + str(len(config['qrzlogger']['station_call'])) + '>' + config['qrzlogger']['station_call']
|
|
|
|
adif += '<call:' + str(len(call)) + '>' + call
|
|
|
|
for field in qso:
|
|
|
|
adif += '<' + field + ':' + str(len(qso[field][1])) + '>' + qso[field][1]
|
|
|
|
adif += '<eor>'
|
|
|
|
|
|
|
|
# construct POST data
|
|
|
|
post_data = { 'KEY' : config['qrzlogger']['api_key'], 'ACTION' : 'INSERT', 'ADIF' : adif }
|
|
|
|
|
|
|
|
# URL encode the payload
|
|
|
|
data = urllib.parse.urlencode(post_data)
|
|
|
|
# send the POST request to QRZ.com
|
2021-05-24 08:46:28 -04:00
|
|
|
response = sendRequest(data)
|
2021-05-21 04:47:02 -04:00
|
|
|
# Check if the upload failed and print out
|
|
|
|
# the reason plus some additional info
|
2021-05-24 08:46:28 -04:00
|
|
|
if response:
|
|
|
|
if "STATUS=FAIL" in response:
|
|
|
|
print(errorcol)
|
|
|
|
print("QSO upload failed. QRZ.com has send the following reason:\n")
|
|
|
|
resp_list = response.split("&")
|
|
|
|
for item in resp_list:
|
|
|
|
print(item)
|
|
|
|
print("\nPlease review the following request that led to this error:\n")
|
|
|
|
print(style.RESET)
|
|
|
|
print(post_data)
|
|
|
|
else:
|
|
|
|
print(successcol)
|
|
|
|
print("QSO successfully uploaded to QRZ.com")
|
|
|
|
print(style.RESET)
|
|
|
|
is_ok = True
|
|
|
|
return is_ok
|
2021-05-21 04:47:02 -04:00
|
|
|
else:
|
2021-05-24 08:46:28 -04:00
|
|
|
print(errorcol + "\nA critical error occured. Please review all previous output." + style.RESET)
|
2021-05-20 12:05:33 -04:00
|
|
|
|
|
|
|
|
2021-05-21 04:47:02 -04:00
|
|
|
# ask a user a simple y/n question
|
|
|
|
# returns True if "y"
|
|
|
|
# returns False in "n"
|
|
|
|
def askUser(question):
|
|
|
|
while True:
|
2021-05-21 10:20:34 -04:00
|
|
|
inp = input("\n" + inputcol + question + " [" + defvalcol + "y/n" + inputcol + "]: " + style.RESET)
|
2021-05-21 04:47:02 -04:00
|
|
|
if inp == "y":
|
|
|
|
return True
|
|
|
|
elif inp == "n":
|
|
|
|
return False
|
2021-05-20 12:05:33 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Main routine
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
2021-05-21 04:47:02 -04:00
|
|
|
keeponlogging = True
|
2021-05-20 12:05:33 -04:00
|
|
|
|
2021-05-21 17:36:05 -04:00
|
|
|
# print an awesome banner
|
2021-05-21 10:20:34 -04:00
|
|
|
print(logocol + " _ ")
|
2021-05-21 04:47:02 -04:00
|
|
|
print(" __ _ _ _ __| |___ __ _ __ _ ___ _ _ ")
|
|
|
|
print(" / _` | '_|_ / / _ \/ _` / _` / -_) '_|")
|
|
|
|
print(" \__, |_| /__|_\___/\__, \__, \___|_| ")
|
2021-05-21 10:20:34 -04:00
|
|
|
print(" |_| |___/|___/ " + style.RESET)
|
2021-05-20 12:05:33 -04:00
|
|
|
|
2021-05-24 08:46:28 -04:00
|
|
|
# get a session after logging into QRZ with user/pass
|
|
|
|
get_session()
|
|
|
|
|
2021-05-21 17:36:05 -04:00
|
|
|
# Begin the main loop
|
2021-05-21 04:47:02 -04:00
|
|
|
while keeponlogging:
|
2021-05-21 17:36:05 -04:00
|
|
|
# query a call sign from the user
|
2021-05-24 06:54:55 -04:00
|
|
|
resume = True
|
2021-05-21 10:20:34 -04:00
|
|
|
call = input("\n\n%sEnter Callsign:%s " % (inputcol, style.RESET))
|
2021-05-21 17:36:05 -04:00
|
|
|
# check if it has the format of a valid call sign
|
|
|
|
# (at least 3 characters, only alphanumeric and slashes)
|
2021-05-24 06:54:55 -04:00
|
|
|
if not (len(call) > 2 and call.replace("/", "").isalnum()):
|
|
|
|
print(errorcol + "\nPlease enter a callsign with\n * at least 3 characters\n * only letters, numbers and slashes" + style.RESET)
|
|
|
|
resume = False
|
|
|
|
if resume:
|
2021-05-21 17:36:05 -04:00
|
|
|
# make the call sign all upper case
|
|
|
|
call = call.upper()
|
|
|
|
# query call sign data from QRZ
|
|
|
|
result = getCallData(call)
|
|
|
|
# the query was successful
|
|
|
|
if result:
|
|
|
|
print ('\n%s%sQRZ.com results for %s%s' % (style.UNDERLINED, hlcol, call, style.RESET))
|
|
|
|
# generate a nice ascii table with the result
|
|
|
|
tab = getXMLQueryTable(result)
|
|
|
|
# print the table
|
|
|
|
print(tablecol)
|
|
|
|
print(tab)
|
|
|
|
print(style.RESET)
|
|
|
|
# the query was unsuccessful
|
2021-05-21 04:47:02 -04:00
|
|
|
else:
|
2021-05-21 17:36:05 -04:00
|
|
|
print ('\n%s%s has no record on QRZ.com ¯\_(ツ)_/¯%s' % (errorcol, call, style.RESET))
|
|
|
|
# ask the user if he/she likes to continue anyway
|
2021-05-24 06:54:55 -04:00
|
|
|
if not askUser("Continue logging this call sign?"):
|
2021-05-21 17:36:05 -04:00
|
|
|
# restart from the beginning
|
2021-05-24 06:54:55 -04:00
|
|
|
resume = False
|
2021-05-21 17:36:05 -04:00
|
|
|
print("")
|
2021-05-24 06:54:55 -04:00
|
|
|
if resume:
|
|
|
|
# pull all previous QSOs from tzhe QRZ logbook
|
|
|
|
result = getQSOsForCallsign(call)
|
|
|
|
# ignore this part if there were no previous QSOs
|
2021-05-24 08:46:28 -04:00
|
|
|
if result and result[0]:
|
2021-05-24 06:54:55 -04:00
|
|
|
print ('%s%sPrevious QSOs with %s%s' % (style.UNDERLINED, hlcol, call, style.RESET))
|
|
|
|
# generate a nice ascii table with the result
|
|
|
|
tab = getQSOTable(result)
|
2021-05-21 17:36:05 -04:00
|
|
|
# print the table
|
|
|
|
print(tablecol)
|
|
|
|
print(tab)
|
|
|
|
print(style.RESET)
|
2021-05-24 06:54:55 -04:00
|
|
|
|
|
|
|
print ('%s%sEnter new QSO details below%s%s (enter \'c\' to cancel)%s\n' % (style.UNDERLINED, hlcol, style.RESET, hlcol, style.RESET,))
|
|
|
|
|
|
|
|
qso_ok = False
|
|
|
|
qso = None
|
|
|
|
|
|
|
|
# we now ask the user for QSO details until he/she is happy with the result
|
|
|
|
while not qso_ok and resume:
|
|
|
|
# query QSO details from the user
|
|
|
|
qso = queryQSOData(qso)
|
|
|
|
# the user has answered all questions
|
|
|
|
if qso:
|
|
|
|
print ('\n%s%sPlease review your choices%s' % (style.UNDERLINED, hlcol, style.RESET))
|
|
|
|
# generate a pretty table
|
|
|
|
tab = getQSODetailTable(qso)
|
|
|
|
# print the table
|
|
|
|
print(tablecol)
|
|
|
|
print(tab)
|
|
|
|
print(style.RESET)
|
|
|
|
# ask user if everything is ok. If not, start over.
|
|
|
|
if askUser("Is this correct?"):
|
|
|
|
qso_ok = sendQSO(qso)
|
|
|
|
# the user has entered 'c' during the QSO detail entering process
|
2021-05-21 17:36:05 -04:00
|
|
|
else:
|
2021-05-24 06:54:55 -04:00
|
|
|
resume = False
|
|
|
|
|
2021-05-21 04:47:02 -04:00
|
|
|
|
2021-05-21 10:20:34 -04:00
|
|
|
print(inputcol)
|
2021-05-21 11:56:55 -04:00
|
|
|
print("73!")
|
2021-05-21 10:20:34 -04:00
|
|
|
print(style.RESET)
|