the user can quit the application any time by entering "quit"
ctrl+c and ctrl+d are now handled
This commit is contained in:
parent
35dae7b23b
commit
f704297c14
|
@ -1,6 +1,6 @@
|
||||||
[metadata]
|
[metadata]
|
||||||
name = qrzlogger
|
name = qrzlogger
|
||||||
version = 0.6.2
|
version = 0.6.5
|
||||||
author = Michael Clemens
|
author = Michael Clemens
|
||||||
author_email = qrzlogger@qrz.is
|
author_email = qrzlogger@qrz.is
|
||||||
description = A python application to log QSOs directly to QRZ.com from the command line
|
description = A python application to log QSOs directly to QRZ.com from the command line
|
||||||
|
|
|
@ -39,7 +39,7 @@ class QRZLogger():
|
||||||
# initialize things
|
# initialize things
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self.version = "0.6.2"
|
self.version = "0.6.5"
|
||||||
|
|
||||||
# Define the configuration object
|
# Define the configuration object
|
||||||
self.config = configparser.ConfigParser()
|
self.config = configparser.ConfigParser()
|
||||||
|
@ -435,6 +435,8 @@ class QRZLogger():
|
||||||
# If not, we keep the data provided by the user
|
# If not, we keep the data provided by the user
|
||||||
if inp == "c":
|
if inp == "c":
|
||||||
return None
|
return None
|
||||||
|
if inp == "quit":
|
||||||
|
sys.exit()
|
||||||
if inp != "":
|
if inp != "":
|
||||||
questions[q][1] = inp
|
questions[q][1] = inp
|
||||||
# check if we are asking for the band
|
# check if we are asking for the band
|
||||||
|
@ -455,11 +457,13 @@ class QRZLogger():
|
||||||
# returns False in "n"
|
# returns False in "n"
|
||||||
def askUser(self, question):
|
def askUser(self, question):
|
||||||
while True:
|
while True:
|
||||||
inp = input("\n" + self.inputcol + question + " [" + self.defvalcol + "y/n" + self.inputcol + "]: " + style.RESET)
|
inp = input("\n" + self.inputcol + question + " [" + self.defvalcol + "y/n/quit" + self.inputcol + "]: " + style.RESET)
|
||||||
if inp == "y":
|
if inp == "y":
|
||||||
return True
|
return True
|
||||||
elif inp == "n":
|
elif inp == "n":
|
||||||
return False
|
return False
|
||||||
|
elif inp == "quit":
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -478,92 +482,95 @@ def main():
|
||||||
|
|
||||||
# Begin the main loop
|
# Begin the main loop
|
||||||
while keeponlogging:
|
while keeponlogging:
|
||||||
# get a session after logging into QRZ with user/pass
|
try:
|
||||||
session_key = q.get_session()
|
# get a session after logging into QRZ with user/pass
|
||||||
# query a call sign from the user
|
session_key = q.get_session()
|
||||||
resume = True
|
# query a call sign from the user
|
||||||
call = input("\n\n%sEnter Callsign:%s " % (q.inputcol, style.RESET))
|
resume = True
|
||||||
# check if it has the format of a valid call sign
|
call = input("\n\n%sEnter Callsign:%s " % (q.inputcol, style.RESET))
|
||||||
# (at least 3 characters, only alphanumeric and slashes)
|
if call == "quit":
|
||||||
if not (len(call) > 2 and call.replace("/", "").isalnum()):
|
sys.exit()
|
||||||
print(q.errorcol + "\nPlease enter a callsign with\n * at least 3 characters\n * only letters, numbers and slashes" + style.RESET)
|
# check if it has the format of a valid call sign
|
||||||
resume = False
|
# (at least 3 characters, only alphanumeric and slashes)
|
||||||
if resume:
|
if not (len(call) > 2 and call.replace("/", "").isalnum()):
|
||||||
# make the call sign all upper case
|
print(q.errorcol + "\nPlease enter a callsign with\n * at least 3 characters\n * only letters, numbers and slashes" + style.RESET)
|
||||||
call = call.upper()
|
resume = False
|
||||||
# query call sign data from QRZ
|
|
||||||
result = q.getCallData(call, session_key)
|
|
||||||
# the query was successful
|
|
||||||
if result:
|
|
||||||
print ('\n%s%sQRZ.com results for %s%s' % (style.UNDERLINED, q.hlcol, call, style.RESET))
|
|
||||||
# generate a nice ascii table with the result
|
|
||||||
tab = q.getXMLQueryTable(result)
|
|
||||||
# print the table
|
|
||||||
print(q.tablecol)
|
|
||||||
print(tab)
|
|
||||||
print(style.RESET)
|
|
||||||
# the query was unsuccessful
|
|
||||||
else:
|
|
||||||
print ('\n%s%s has no record on QRZ.com ¯\_(ツ)_/¯%s' % (q.errorcol, call, style.RESET))
|
|
||||||
# ask the user if he/she likes to continue anyway
|
|
||||||
if not q.askUser("Continue logging this call sign?"):
|
|
||||||
# restart from the beginning
|
|
||||||
resume = False
|
|
||||||
print("")
|
|
||||||
if resume:
|
if resume:
|
||||||
# pull all previous QSOs from tzhe QRZ logbook
|
# make the call sign all upper case
|
||||||
result = q.getQSOs("CALL:"+ call)
|
call = call.upper()
|
||||||
# ignore this part if there were no previous QSOs
|
# query call sign data from QRZ
|
||||||
if result and result[0]:
|
result = q.getCallData(call, session_key)
|
||||||
print ('%s%sPrevious QSOs with %s%s' % (style.UNDERLINED, q.hlcol, call, style.RESET))
|
# the query was successful
|
||||||
|
if result:
|
||||||
|
print ('\n%s%sQRZ.com results for %s%s' % (style.UNDERLINED, q.hlcol, call, style.RESET))
|
||||||
# generate a nice ascii table with the result
|
# generate a nice ascii table with the result
|
||||||
tab = q.getQSOTable(result)
|
tab = q.getXMLQueryTable(result)
|
||||||
# print the table
|
# print the table
|
||||||
print(q.tablecol)
|
print(q.tablecol)
|
||||||
print(tab)
|
print(tab)
|
||||||
print(style.RESET)
|
print(style.RESET)
|
||||||
|
# the query was unsuccessful
|
||||||
print ('%s%sEnter new QSO details below%s%s (enter \'c\' to cancel)%s\n' % (style.UNDERLINED, q.hlcol, style.RESET, q.hlcol, style.RESET,))
|
else:
|
||||||
|
print ('\n%s%s has no record on QRZ.com ¯\_(ツ)_/¯%s' % (q.errorcol, call, style.RESET))
|
||||||
qso_ok = False
|
# ask the user if he/she likes to continue anyway
|
||||||
qso = None
|
if not q.askUser("Continue logging this call sign?"):
|
||||||
|
# restart from the beginning
|
||||||
# we now ask the user for QSO details until he/she is happy with the result
|
resume = False
|
||||||
while not qso_ok and resume:
|
print("")
|
||||||
# query QSO details from the user
|
if resume:
|
||||||
qso = q.queryQSOData(qso)
|
# pull all previous QSOs from tzhe QRZ logbook
|
||||||
# the user has answered all questions
|
result = q.getQSOs("CALL:"+ call)
|
||||||
if qso:
|
# ignore this part if there were no previous QSOs
|
||||||
print ('\n%s%sPlease review your choices%s' % (style.UNDERLINED, q.hlcol, style.RESET))
|
if result and result[0]:
|
||||||
# generate a pretty table
|
print ('%s%sPrevious QSOs with %s%s' % (style.UNDERLINED, q.hlcol, call, style.RESET))
|
||||||
tab = q.getQSODetailTable(qso)
|
# generate a nice ascii table with the result
|
||||||
|
tab = q.getQSOTable(result)
|
||||||
# print the table
|
# print the table
|
||||||
print(q.tablecol)
|
print(q.tablecol)
|
||||||
print(tab)
|
print(tab)
|
||||||
print(style.RESET)
|
print(style.RESET)
|
||||||
# ask user if everything is ok. If not, start over.
|
|
||||||
if q.askUser("Is this correct?"):
|
|
||||||
logid = q.sendQSO(qso, call)
|
|
||||||
if logid and logid != "null":
|
|
||||||
# pull the uploaded QSO from QRZ
|
|
||||||
result = q.getQSOs("LOGIDS:"+ logid)
|
|
||||||
if result and result[0]:
|
|
||||||
#print ('%sQSO uploaded to QRZ.com:%s' % (hlcol, style.RESET))
|
|
||||||
# generate a nice ascii table with the result
|
|
||||||
tab = q.getQSOTable(result)
|
|
||||||
# print the table
|
|
||||||
print(q.tablecol)
|
|
||||||
print(tab)
|
|
||||||
print(style.RESET)
|
|
||||||
qso_ok = True
|
|
||||||
# the user has entered 'c' during the QSO detail entering process
|
|
||||||
else:
|
|
||||||
resume = False
|
|
||||||
|
|
||||||
print(q.inputcol)
|
print ('%s%sEnter new QSO details below%s%s (enter \'c\' to cancel)%s\n' % (style.UNDERLINED, q.hlcol, style.RESET, q.hlcol, style.RESET,))
|
||||||
print("73!")
|
|
||||||
print(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 = q.queryQSOData(qso)
|
||||||
|
# the user has answered all questions
|
||||||
|
if qso:
|
||||||
|
print ('\n%s%sPlease review your choices%s' % (style.UNDERLINED, q.hlcol, style.RESET))
|
||||||
|
# generate a pretty table
|
||||||
|
tab = q.getQSODetailTable(qso)
|
||||||
|
# print the table
|
||||||
|
print(q.tablecol)
|
||||||
|
print(tab)
|
||||||
|
print(style.RESET)
|
||||||
|
# ask user if everything is ok. If not, start over.
|
||||||
|
if q.askUser("Is this correct?"):
|
||||||
|
logid = q.sendQSO(qso, call)
|
||||||
|
if logid and logid != "null":
|
||||||
|
# pull the uploaded QSO from QRZ
|
||||||
|
result = q.getQSOs("LOGIDS:"+ logid)
|
||||||
|
if result and result[0]:
|
||||||
|
#print ('%sQSO uploaded to QRZ.com:%s' % (hlcol, style.RESET))
|
||||||
|
# generate a nice ascii table with the result
|
||||||
|
tab = q.getQSOTable(result)
|
||||||
|
# print the table
|
||||||
|
print(q.tablecol)
|
||||||
|
print(tab)
|
||||||
|
print(style.RESET)
|
||||||
|
qso_ok = True
|
||||||
|
# the user has entered 'c' during the QSO detail entering process
|
||||||
|
else:
|
||||||
|
resume = False
|
||||||
|
except:
|
||||||
|
print("\n\n73!\n")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue