mirror of
https://codeberg.org/mclemens/qrzlogger.git
synced 2025-01-05 06:16:27 -05:00
qrzlogger now queries CALL if CALL/SUFFIX could not be found
better exception handling for ctrl+c and ctrl+d implemented gracefull exit handling qrzlogger no longer asks the user to continue if no call data was found
This commit is contained in:
parent
f704297c14
commit
b2665aaf42
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = qrzlogger
|
name = qrzlogger
|
||||||
version = 0.6.5
|
version = 0.6.6
|
||||||
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
|
||||||
|
@ -32,6 +32,8 @@ from datetime import date
|
|||||||
from datetime import timezone
|
from datetime import timezone
|
||||||
import configparser
|
import configparser
|
||||||
from colored import fore, back, style
|
from colored import fore, back, style
|
||||||
|
import signal
|
||||||
|
import atexit
|
||||||
|
|
||||||
|
|
||||||
class QRZLogger():
|
class QRZLogger():
|
||||||
@ -39,7 +41,7 @@ class QRZLogger():
|
|||||||
# initialize things
|
# initialize things
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self.version = "0.6.5"
|
self.version = "0.6.6"
|
||||||
|
|
||||||
# Define the configuration object
|
# Define the configuration object
|
||||||
self.config = configparser.ConfigParser()
|
self.config = configparser.ConfigParser()
|
||||||
@ -152,6 +154,25 @@ class QRZLogger():
|
|||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
# returns the actual call sign without any indicators
|
||||||
|
# (e.g, "/p" or "F/")
|
||||||
|
def removeIndicators(self, call):
|
||||||
|
cleaned_call = call
|
||||||
|
if call.endswith(("/P","/M","/QRP")):
|
||||||
|
cleaned_call = re.sub(r'/\w$', "", call)
|
||||||
|
if "/" in cleaned_call:
|
||||||
|
cleaned_call = re.sub(r'^\w+/', "", cleaned_call)
|
||||||
|
return cleaned_call
|
||||||
|
|
||||||
|
|
||||||
|
# Print the table object to stdout
|
||||||
|
def printTable(self, tab):
|
||||||
|
print(self.tablecol)
|
||||||
|
print(tab)
|
||||||
|
print(style.RESET)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#####################################################
|
#####################################################
|
||||||
# QRZ.com API Functions #
|
# QRZ.com API Functions #
|
||||||
#####################################################
|
#####################################################
|
||||||
@ -452,18 +473,13 @@ class QRZLogger():
|
|||||||
return questions
|
return questions
|
||||||
|
|
||||||
|
|
||||||
# ask a user a simple y/n question
|
def handler(signum, frame):
|
||||||
# returns True if "y"
|
return None
|
||||||
# returns False in "n"
|
|
||||||
def askUser(self, question):
|
|
||||||
while True:
|
# Prints a message when the application is terminated
|
||||||
inp = input("\n" + self.inputcol + question + " [" + self.defvalcol + "y/n/quit" + self.inputcol + "]: " + style.RESET)
|
def quit_gracefully():
|
||||||
if inp == "y":
|
print("\n73!\n")
|
||||||
return True
|
|
||||||
elif inp == "n":
|
|
||||||
return False
|
|
||||||
elif inp == "quit":
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -471,9 +487,11 @@ class QRZLogger():
|
|||||||
# Main Routine #
|
# Main Routine #
|
||||||
#####################################################
|
#####################################################
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
|
signal.signal(signal.SIGINT, handler)
|
||||||
|
atexit.register(quit_gracefully)
|
||||||
|
|
||||||
q = QRZLogger()
|
q = QRZLogger()
|
||||||
q.printBanner()
|
q.printBanner()
|
||||||
|
|
||||||
@ -482,11 +500,9 @@ def main():
|
|||||||
|
|
||||||
# Begin the main loop
|
# Begin the main loop
|
||||||
while keeponlogging:
|
while keeponlogging:
|
||||||
try:
|
|
||||||
# get a session after logging into QRZ with user/pass
|
# get a session after logging into QRZ with user/pass
|
||||||
session_key = q.get_session()
|
session_key = q.get_session()
|
||||||
# query a call sign from the user
|
# query a call sign from the user
|
||||||
resume = True
|
|
||||||
call = input("\n\n%sEnter Callsign:%s " % (q.inputcol, style.RESET))
|
call = input("\n\n%sEnter Callsign:%s " % (q.inputcol, style.RESET))
|
||||||
if call == "quit":
|
if call == "quit":
|
||||||
sys.exit()
|
sys.exit()
|
||||||
@ -494,8 +510,7 @@ def main():
|
|||||||
# (at least 3 characters, only alphanumeric and slashes)
|
# (at least 3 characters, only alphanumeric and slashes)
|
||||||
if not (len(call) > 2 and call.replace("/", "").isalnum()):
|
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)
|
print(q.errorcol + "\nPlease enter a callsign with\n * at least 3 characters\n * only letters, numbers and slashes" + style.RESET)
|
||||||
resume = False
|
continue
|
||||||
if resume:
|
|
||||||
# make the call sign all upper case
|
# make the call sign all upper case
|
||||||
call = call.upper()
|
call = call.upper()
|
||||||
# query call sign data from QRZ
|
# query call sign data from QRZ
|
||||||
@ -504,73 +519,70 @@ def main():
|
|||||||
if result:
|
if result:
|
||||||
print ('\n%s%sQRZ.com results for %s%s' % (style.UNDERLINED, q.hlcol, call, style.RESET))
|
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.getXMLQueryTable(result)
|
q.printTable(q.getXMLQueryTable(result))
|
||||||
# print the table
|
|
||||||
print(q.tablecol)
|
|
||||||
print(tab)
|
|
||||||
print(style.RESET)
|
|
||||||
# the query was unsuccessful
|
# the query was unsuccessful
|
||||||
else:
|
else:
|
||||||
print ('\n%s%s has no record on QRZ.com ¯\_(ツ)_/¯%s' % (q.errorcol, call, style.RESET))
|
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
|
cleaned_call = q.removeIndicators(call)
|
||||||
if not q.askUser("Continue logging this call sign?"):
|
if call != cleaned_call:
|
||||||
# restart from the beginning
|
# query call sign data from QRZ
|
||||||
resume = False
|
result = q.getCallData(cleaned_call, session_key)
|
||||||
|
# the query was successful
|
||||||
|
if result:
|
||||||
|
print ('\n%s%sShowing results for %s instead%s' % (style.UNDERLINED, q.hlcol, cleaned_call, style.RESET))
|
||||||
|
# generate a nice ascii table with the result
|
||||||
|
q.printTable(q.getXMLQueryTable(result))
|
||||||
print("")
|
print("")
|
||||||
if resume:
|
|
||||||
# pull all previous QSOs from tzhe QRZ logbook
|
# pull all previous QSOs from tzhe QRZ logbook
|
||||||
result = q.getQSOs("CALL:"+ call)
|
result = q.getQSOs("CALL:"+ call)
|
||||||
# ignore this part if there were no previous QSOs
|
# ignore this part if there were no previous QSOs
|
||||||
if result and result[0]:
|
if result and result[0]:
|
||||||
print ('%s%sPrevious QSOs with %s%s' % (style.UNDERLINED, q.hlcol, call, style.RESET))
|
print ('%s%sPrevious QSOs with %s%s' % (style.UNDERLINED, q.hlcol, call, style.RESET))
|
||||||
# generate a nice ascii table with the result
|
q.printTable(q.getQSOTable(result))
|
||||||
tab = q.getQSOTable(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,))
|
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
|
done = False
|
||||||
qso = None
|
qso = None
|
||||||
|
|
||||||
# we now ask the user for QSO details until he/she is happy with the result
|
# we now ask the user for QSO details until he/she is happy with the result
|
||||||
while not qso_ok and resume:
|
resume = True
|
||||||
|
while not done:
|
||||||
# query QSO details from the user
|
# query QSO details from the user
|
||||||
qso = q.queryQSOData(qso)
|
qso = q.queryQSOData(qso)
|
||||||
# the user has answered all questions
|
# the user has answered all questions
|
||||||
if qso:
|
if qso:
|
||||||
print ('\n%s%sPlease review your choices%s' % (style.UNDERLINED, q.hlcol, style.RESET))
|
print ('\n%s%sPlease review your choices%s' % (style.UNDERLINED, q.hlcol, style.RESET))
|
||||||
# generate a pretty table
|
q.printTable(q.getQSODetailTable(qso))
|
||||||
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.
|
# ask user if everything is ok. If not, start over.
|
||||||
if q.askUser("Is this correct?"):
|
while True:
|
||||||
|
answer = input("\n" + q.inputcol + "Is this correct? [" + q.defvalcol + "y/n/c/quit" + q.inputcol + "]: " + style.RESET)
|
||||||
|
answer = answer.upper()
|
||||||
|
if answer == "Y":
|
||||||
logid = q.sendQSO(qso, call)
|
logid = q.sendQSO(qso, call)
|
||||||
if logid and logid != "null":
|
if logid and logid != "null":
|
||||||
# pull the uploaded QSO from QRZ
|
# pull the uploaded QSO from QRZ
|
||||||
result = q.getQSOs("LOGIDS:"+ logid)
|
result = q.getQSOs("LOGIDS:"+ logid)
|
||||||
if result and result[0]:
|
if result and result[0]:
|
||||||
#print ('%sQSO uploaded to QRZ.com:%s' % (hlcol, style.RESET))
|
q.printTable(q.getQSOTable(result))
|
||||||
# generate a nice ascii table with the result
|
done = True
|
||||||
tab = q.getQSOTable(result)
|
break
|
||||||
# print the table
|
elif answer == "C":
|
||||||
print(q.tablecol)
|
done = True
|
||||||
print(tab)
|
break
|
||||||
print(style.RESET)
|
elif answer == "N":
|
||||||
qso_ok = True
|
break
|
||||||
|
elif answer == "QUIT":
|
||||||
|
sys.exit()
|
||||||
# the user has entered 'c' during the QSO detail entering process
|
# the user has entered 'c' during the QSO detail entering process
|
||||||
else:
|
else:
|
||||||
resume = False
|
done = True
|
||||||
except:
|
continue
|
||||||
print("\n\n73!\n")
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
except EOFError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user