mirror of
https://codeberg.org/mclemens/qrzlogger.git
synced 2024-10-04 08:56:13 -04:00
added more comments
the user can now cancel the QSO entering process added callsign plausability check
This commit is contained in:
parent
08905c69af
commit
4dad3d2d2f
46
qrzlogger.py
46
qrzlogger.py
@ -110,14 +110,7 @@ def getCallData(call):
|
|||||||
|
|
||||||
xml_url = """https://xmldata.QRZ.com/xml/current/?s={0}&callsign={1}""" .format(session_key, call)
|
xml_url = """https://xmldata.QRZ.com/xml/current/?s={0}&callsign={1}""" .format(session_key, call)
|
||||||
r = session.get(xml_url)
|
r = session.get(xml_url)
|
||||||
if r.status_code != 200:
|
|
||||||
print("nope")
|
|
||||||
raw = xmltodict.parse(r.content).get('QRZDatabase')
|
raw = xmltodict.parse(r.content).get('QRZDatabase')
|
||||||
if not raw:
|
|
||||||
print("nope")
|
|
||||||
if raw['Session'].get('Error'):
|
|
||||||
errormsg = raw['Session'].get('Error')
|
|
||||||
else:
|
|
||||||
calldata = raw.get('Callsign')
|
calldata = raw.get('Callsign')
|
||||||
if calldata:
|
if calldata:
|
||||||
return calldata
|
return calldata
|
||||||
@ -252,6 +245,8 @@ def queryQSOData(qso):
|
|||||||
inp = input(txt)
|
inp = input(txt)
|
||||||
# If the user just hits enter, we keep the default value.
|
# If the user just hits enter, we keep the default value.
|
||||||
# If not, we keep the data provided by the user
|
# If not, we keep the data provided by the user
|
||||||
|
if inp == "c":
|
||||||
|
return None
|
||||||
if inp != "":
|
if inp != "":
|
||||||
questions[q][1] = inp
|
questions[q][1] = inp
|
||||||
|
|
||||||
@ -314,51 +309,72 @@ def askUser(question):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
keeponlogging = True
|
keeponlogging = True
|
||||||
|
# get a session after logging into QRZ with user/pass
|
||||||
get_session()
|
get_session()
|
||||||
|
|
||||||
|
# print an awesome banner
|
||||||
print(logocol + " _ ")
|
print(logocol + " _ ")
|
||||||
print(" __ _ _ _ __| |___ __ _ __ _ ___ _ _ ")
|
print(" __ _ _ _ __| |___ __ _ __ _ ___ _ _ ")
|
||||||
print(" / _` | '_|_ / / _ \/ _` / _` / -_) '_|")
|
print(" / _` | '_|_ / / _ \/ _` / _` / -_) '_|")
|
||||||
print(" \__, |_| /__|_\___/\__, \__, \___|_| ")
|
print(" \__, |_| /__|_\___/\__, \__, \___|_| ")
|
||||||
print(" |_| |___/|___/ " + style.RESET)
|
print(" |_| |___/|___/ " + style.RESET)
|
||||||
|
|
||||||
|
# Begin the main loop
|
||||||
while keeponlogging:
|
while keeponlogging:
|
||||||
|
# query a call sign from the user
|
||||||
call = input("\n\n%sEnter Callsign:%s " % (inputcol, style.RESET))
|
call = input("\n\n%sEnter Callsign:%s " % (inputcol, style.RESET))
|
||||||
|
# check if it has the format of a valid call sign
|
||||||
|
# (at least 3 characters, only alphanumeric and slashes)
|
||||||
|
if len(call) > 2 and call.replace("/", "").isalnum():
|
||||||
|
# make the call sign all upper case
|
||||||
call = call.upper()
|
call = call.upper()
|
||||||
|
# query call sign data from QRZ
|
||||||
result = getCallData(call)
|
result = getCallData(call)
|
||||||
|
# the query was successful
|
||||||
if result:
|
if result:
|
||||||
print ('\n%s%sQRZ.com results for %s%s' % (style.UNDERLINED, hlcol, call, style.RESET))
|
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)
|
tab = getXMLQueryTable(result)
|
||||||
|
# print the table
|
||||||
print(tablecol)
|
print(tablecol)
|
||||||
print(tab)
|
print(tab)
|
||||||
print(style.RESET)
|
print(style.RESET)
|
||||||
|
# the query was unsuccessful
|
||||||
else:
|
else:
|
||||||
print ('\n%s%s has no record on QRZ.com ¯\_(ツ)_/¯%s' % (errorcol, call, style.RESET))
|
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
|
||||||
if not askUser("Continue with logging this QSO?"):
|
if not askUser("Continue with logging this QSO?"):
|
||||||
|
# restart from the beginning
|
||||||
break
|
break
|
||||||
print("")
|
print("")
|
||||||
|
# pull all previous QSOs from tzhe QRZ logbook
|
||||||
result = getQSOsForCallsign(call)
|
result = getQSOsForCallsign(call)
|
||||||
|
# ignore this part if there were no previous QSOs
|
||||||
if result[0]:
|
if result[0]:
|
||||||
print ('%s%sPrevious QSOs with %s%s' % (style.UNDERLINED, hlcol, call, style.RESET))
|
print ('%s%sPrevious QSOs with %s%s' % (style.UNDERLINED, hlcol, call, style.RESET))
|
||||||
|
# generate a nice ascii table with the result
|
||||||
tab = getQSOTable(result)
|
tab = getQSOTable(result)
|
||||||
|
# print the table
|
||||||
print(tablecol)
|
print(tablecol)
|
||||||
print(tab)
|
print(tab)
|
||||||
print(style.RESET)
|
print(style.RESET)
|
||||||
|
|
||||||
print ('%s%sEnter new QSO details below%s\n' % (style.UNDERLINED, hlcol, style.RESET))
|
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_ok = False
|
||||||
qso = None
|
qso = None
|
||||||
ask_try_again = False
|
ask_try_again = False
|
||||||
|
|
||||||
|
# we now ask the user for QSO details until he/she is happy with the result
|
||||||
while not qso_ok:
|
while not qso_ok:
|
||||||
# query QSO details from thbe user
|
# query QSO details from the user
|
||||||
qso = queryQSOData(qso)
|
qso = queryQSOData(qso)
|
||||||
|
# the user has answered all questions
|
||||||
|
if qso:
|
||||||
print ('\n%s%sPlease review your choices%s' % (style.UNDERLINED, hlcol, style.RESET))
|
print ('\n%s%sPlease review your choices%s' % (style.UNDERLINED, hlcol, style.RESET))
|
||||||
# generate a pretty table
|
# generate a pretty table
|
||||||
tab = getQSODetailTable(qso)
|
tab = getQSODetailTable(qso)
|
||||||
|
# print the table
|
||||||
print(tablecol)
|
print(tablecol)
|
||||||
print(tab)
|
print(tab)
|
||||||
print(style.RESET)
|
print(style.RESET)
|
||||||
@ -385,6 +401,14 @@ if __name__ == '__main__':
|
|||||||
if not askUser("Log another QSO?"):
|
if not askUser("Log another QSO?"):
|
||||||
# quit the application
|
# quit the application
|
||||||
keeponlogging = False
|
keeponlogging = False
|
||||||
|
# the user has entered 'c' during the QSO detail entering process
|
||||||
|
else:
|
||||||
|
qso_ok = True
|
||||||
|
qso = None
|
||||||
|
# the user entered a too short callsign or invalid characters
|
||||||
|
else:
|
||||||
|
print(errorcol + "\nPlease enter a callsign with\n * at least 3 characters\n * only letters, numbers and slashes" + style.RESET)
|
||||||
|
|
||||||
|
|
||||||
print(inputcol)
|
print(inputcol)
|
||||||
print("73!")
|
print("73!")
|
||||||
|
Loading…
Reference in New Issue
Block a user