mirror of
https://codeberg.org/mclemens/qrzlogger.git
synced 2025-02-21 06:57:36 -05:00
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]
|
||||
name = qrzlogger
|
||||
version = 0.6.2
|
||||
version = 0.6.5
|
||||
author = Michael Clemens
|
||||
author_email = qrzlogger@qrz.is
|
||||
description = A python application to log QSOs directly to QRZ.com from the command line
|
||||
|
@ -39,7 +39,7 @@ class QRZLogger():
|
||||
# initialize things
|
||||
def __init__(self):
|
||||
|
||||
self.version = "0.6.2"
|
||||
self.version = "0.6.5"
|
||||
|
||||
# Define the configuration object
|
||||
self.config = configparser.ConfigParser()
|
||||
@ -435,6 +435,8 @@ class QRZLogger():
|
||||
# If not, we keep the data provided by the user
|
||||
if inp == "c":
|
||||
return None
|
||||
if inp == "quit":
|
||||
sys.exit()
|
||||
if inp != "":
|
||||
questions[q][1] = inp
|
||||
# check if we are asking for the band
|
||||
@ -455,11 +457,13 @@ class QRZLogger():
|
||||
# returns False in "n"
|
||||
def askUser(self, question):
|
||||
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":
|
||||
return True
|
||||
elif inp == "n":
|
||||
return False
|
||||
elif inp == "quit":
|
||||
sys.exit()
|
||||
|
||||
|
||||
|
||||
@ -478,92 +482,95 @@ def main():
|
||||
|
||||
# Begin the main loop
|
||||
while keeponlogging:
|
||||
# get a session after logging into QRZ with user/pass
|
||||
session_key = q.get_session()
|
||||
# query a call sign from the user
|
||||
resume = True
|
||||
call = input("\n\n%sEnter Callsign:%s " % (q.inputcol, style.RESET))
|
||||
# check if it has the format of a valid call sign
|
||||
# (at least 3 characters, only alphanumeric and slashes)
|
||||
if not (len(call) > 2 and call.replace("/", "").isalnum()):
|
||||
print(q.errorcol + "\nPlease enter a callsign with\n * at least 3 characters\n * only letters, numbers and slashes" + style.RESET)
|
||||
resume = False
|
||||
if resume:
|
||||
# make the call sign all upper case
|
||||
call = call.upper()
|
||||
# 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("")
|
||||
try:
|
||||
# get a session after logging into QRZ with user/pass
|
||||
session_key = q.get_session()
|
||||
# query a call sign from the user
|
||||
resume = True
|
||||
call = input("\n\n%sEnter Callsign:%s " % (q.inputcol, style.RESET))
|
||||
if call == "quit":
|
||||
sys.exit()
|
||||
# check if it has the format of a valid call sign
|
||||
# (at least 3 characters, only alphanumeric and slashes)
|
||||
if not (len(call) > 2 and call.replace("/", "").isalnum()):
|
||||
print(q.errorcol + "\nPlease enter a callsign with\n * at least 3 characters\n * only letters, numbers and slashes" + style.RESET)
|
||||
resume = False
|
||||
if resume:
|
||||
# pull all previous QSOs from tzhe QRZ logbook
|
||||
result = q.getQSOs("CALL:"+ call)
|
||||
# ignore this part if there were no previous QSOs
|
||||
if result and result[0]:
|
||||
print ('%s%sPrevious QSOs with %s%s' % (style.UNDERLINED, q.hlcol, call, style.RESET))
|
||||
# make the call sign all upper case
|
||||
call = call.upper()
|
||||
# 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.getQSOTable(result)
|
||||
tab = q.getXMLQueryTable(result)
|
||||
# print the table
|
||||
print(q.tablecol)
|
||||
print(tab)
|
||||
print(style.RESET)
|
||||
|
||||
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,))
|
||||
|
||||
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)
|
||||
# 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:
|
||||
# pull all previous QSOs from tzhe QRZ logbook
|
||||
result = q.getQSOs("CALL:"+ call)
|
||||
# ignore this part if there were no previous QSOs
|
||||
if result and result[0]:
|
||||
print ('%s%sPrevious QSOs with %s%s' % (style.UNDERLINED, q.hlcol, call, 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)
|
||||
# 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("73!")
|
||||
print(style.RESET)
|
||||
|
||||
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,))
|
||||
|
||||
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__":
|
||||
sys.exit(main())
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user