mirror of
https://codeberg.org/mclemens/qrzlogger.git
synced 2024-11-19 06:26:02 -05:00
added colored text
This commit is contained in:
parent
38c23e4541
commit
f5d1cf49dd
@ -14,13 +14,14 @@ It does the following:
|
|||||||
|
|
||||||
qrzlogger needs the following libraries:
|
qrzlogger needs the following libraries:
|
||||||
|
|
||||||
* python3-xmltodict
|
* xmltodict
|
||||||
* python3-prettytable
|
* prettytable
|
||||||
|
* colored
|
||||||
|
|
||||||
These libraries can be installed with the following command on Debian Linux based operating systems:
|
These libraries can be installed with the following command on Debian Linux based operating systems:
|
||||||
|
|
||||||
```
|
```
|
||||||
# sudo apt install python3-xmltodict python3-prettytable
|
# sudo apt install python3-xmltodict python3-prettytable python3-colored
|
||||||
```
|
```
|
||||||
|
|
||||||
Furthermore, you need at least the XML subscription from QRZ.com.
|
Furthermore, you need at least the XML subscription from QRZ.com.
|
||||||
|
@ -12,3 +12,13 @@ mode = SSB
|
|||||||
rst_rcvd = 59
|
rst_rcvd = 59
|
||||||
rst_sent = 59
|
rst_sent = 59
|
||||||
tx_pwr = 5
|
tx_pwr = 5
|
||||||
|
|
||||||
|
#colors
|
||||||
|
use_colors = yes
|
||||||
|
inputcol = fore.YELLOW
|
||||||
|
hlcol = fore.YELLOW
|
||||||
|
defvalcol = fore.LIGHT_BLUE
|
||||||
|
errorcol = fore.RED
|
||||||
|
successcol = fore.GREEN
|
||||||
|
tablecol = fore.LIGHT_BLUE
|
||||||
|
logocol = fore.YELLOW
|
||||||
|
73
qrzlogger.py
73
qrzlogger.py
@ -52,6 +52,7 @@ from requests.structures import CaseInsensitiveDict
|
|||||||
from datetime import date
|
from datetime import date
|
||||||
from datetime import timezone
|
from datetime import timezone
|
||||||
import configparser
|
import configparser
|
||||||
|
from colored import fore, back, style
|
||||||
|
|
||||||
# read the config file
|
# read the config file
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
@ -64,6 +65,24 @@ headers["Content-Type"] = "application/x-www-form-urlencoded"
|
|||||||
session = None
|
session = None
|
||||||
session_key = None
|
session_key = None
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
|
||||||
# Generate a session for QRZ.com's xml service with
|
# Generate a session for QRZ.com's xml service with
|
||||||
# the help of the QRZ.com username and password
|
# the help of the QRZ.com username and password
|
||||||
@ -213,14 +232,14 @@ def queryQSOData(qso):
|
|||||||
# then we use defaults
|
# then we use defaults
|
||||||
if qso is None:
|
if qso is None:
|
||||||
questions = {
|
questions = {
|
||||||
"qso_date" : ["QSO Date: ",qso_date],
|
"qso_date" : ["QSO Date",qso_date],
|
||||||
"time_on": ["QSO Time: ", time_on],
|
"time_on": ["QSO Time", time_on],
|
||||||
"band": ["Band: ", band],
|
"band": ["Band", band],
|
||||||
"mode": ["Mode: ", mode],
|
"mode": ["Mode", mode],
|
||||||
"rst_rcvd": ["RST Received: ", rst_rcvd],
|
"rst_rcvd": ["RST Received", rst_rcvd],
|
||||||
"rst_sent": ["RST Sent: ", rst_sent],
|
"rst_sent": ["RST Sent", rst_sent],
|
||||||
"tx_pwr": ["Power (in W): ", tx_pwr],
|
"tx_pwr": ["Power (in W)", tx_pwr],
|
||||||
"comment": ["Comment: ", comment]
|
"comment": ["Comment", comment]
|
||||||
}
|
}
|
||||||
# if this is not the first try, we pre-fill the
|
# if this is not the first try, we pre-fill the
|
||||||
# vaulues we got from the last try
|
# vaulues we got from the last try
|
||||||
@ -230,7 +249,8 @@ def queryQSOData(qso):
|
|||||||
# We now loop through all defined fields and ask
|
# We now loop through all defined fields and ask
|
||||||
# the user for input
|
# the user for input
|
||||||
for q in questions:
|
for q in questions:
|
||||||
inp = input(questions[q][0]+" ["+questions[q][1]+"]: " )
|
txt = inputcol + questions[q][0] + " [" + defvalcol + questions[q][1] + inputcol + "]:" + style.RESET
|
||||||
|
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 != "":
|
if inp != "":
|
||||||
@ -251,8 +271,6 @@ def sendQSO(qso):
|
|||||||
adif += '<' + field + ':' + str(len(qso[field][1])) + '>' + qso[field][1]
|
adif += '<' + field + ':' + str(len(qso[field][1])) + '>' + qso[field][1]
|
||||||
adif += '<eor>'
|
adif += '<eor>'
|
||||||
|
|
||||||
print(adif)
|
|
||||||
|
|
||||||
# construct POST data
|
# construct POST data
|
||||||
post_data = { 'KEY' : config['qrzlogger']['api_key'], 'ACTION' : 'INSERT', 'ADIF' : adif }
|
post_data = { 'KEY' : config['qrzlogger']['api_key'], 'ACTION' : 'INSERT', 'ADIF' : adif }
|
||||||
|
|
||||||
@ -265,14 +283,18 @@ def sendQSO(qso):
|
|||||||
# Check if the upload failed and print out
|
# Check if the upload failed and print out
|
||||||
# the reason plus some additional info
|
# the reason plus some additional info
|
||||||
if "STATUS=FAIL" in response:
|
if "STATUS=FAIL" in response:
|
||||||
print("\nQSO upload failed. QRZ.com has send the following reason:\n")
|
print(errorcol)
|
||||||
|
print("QSO upload failed. QRZ.com has send the following reason:\n")
|
||||||
resp_list = response.split("&")
|
resp_list = response.split("&")
|
||||||
for item in resp_list:
|
for item in resp_list:
|
||||||
print(item)
|
print(item)
|
||||||
print("\nPlease review the following request that led to this error:\n")
|
print("\nPlease review the following request that led to this error:\n")
|
||||||
|
print(style.RESET)
|
||||||
print(post_data)
|
print(post_data)
|
||||||
else:
|
else:
|
||||||
|
print(successcol)
|
||||||
print("QSO successfully uploaded to QRZ.com")
|
print("QSO successfully uploaded to QRZ.com")
|
||||||
|
print(style.RESET)
|
||||||
is_ok = True
|
is_ok = True
|
||||||
return is_ok
|
return is_ok
|
||||||
|
|
||||||
@ -282,7 +304,7 @@ def sendQSO(qso):
|
|||||||
# returns False in "n"
|
# returns False in "n"
|
||||||
def askUser(question):
|
def askUser(question):
|
||||||
while True:
|
while True:
|
||||||
inp = input("\n" + question + " [y/n]: ")
|
inp = input("\n" + inputcol + question + " [" + defvalcol + "y/n" + inputcol + "]: " + style.RESET)
|
||||||
if inp == "y":
|
if inp == "y":
|
||||||
return True
|
return True
|
||||||
elif inp == "n":
|
elif inp == "n":
|
||||||
@ -295,28 +317,33 @@ if __name__ == '__main__':
|
|||||||
keeponlogging = True
|
keeponlogging = True
|
||||||
get_session()
|
get_session()
|
||||||
|
|
||||||
print(" _ ")
|
print(logocol + " _ ")
|
||||||
print(" __ _ _ _ __| |___ __ _ __ _ ___ _ _ ")
|
print(" __ _ _ _ __| |___ __ _ __ _ ___ _ _ ")
|
||||||
print(" / _` | '_|_ / / _ \/ _` / _` / -_) '_|")
|
print(" / _` | '_|_ / / _ \/ _` / _` / -_) '_|")
|
||||||
print(" \__, |_| /__|_\___/\__, \__, \___|_| ")
|
print(" \__, |_| /__|_\___/\__, \__, \___|_| ")
|
||||||
print(" |_| |___/|___/ ")
|
print(" |_| |___/|___/ " + style.RESET)
|
||||||
|
|
||||||
while keeponlogging:
|
while keeponlogging:
|
||||||
call = input("\n\nEnter Callsign: ")
|
call = input("\n\n%sEnter Callsign:%s " % (inputcol, style.RESET))
|
||||||
|
call = call.upper()
|
||||||
|
|
||||||
print('\nQRZ.com results for {0}:\n'.format(call))
|
print ('\n%s%sQRZ.com results for %s%s' % (style.UNDERLINED, hlcol, call, style.RESET))
|
||||||
|
|
||||||
result = getCallData(call)
|
result = getCallData(call)
|
||||||
tab = getXMLQueryTable(result)
|
tab = getXMLQueryTable(result)
|
||||||
|
print(tablecol)
|
||||||
print(tab)
|
print(tab)
|
||||||
|
print(style.RESET)
|
||||||
|
|
||||||
print('\n\nPrevious QSOs with {0}:\n'.format(call))
|
print ('%s%sPrevious QSOs with %s%s' % (style.UNDERLINED, hlcol, call, style.RESET))
|
||||||
|
|
||||||
result = getQSOsForCallsign(call)
|
result = getQSOsForCallsign(call)
|
||||||
tab = getQSOTable(result)
|
tab = getQSOTable(result)
|
||||||
|
print(tablecol)
|
||||||
print(tab)
|
print(tab)
|
||||||
|
print(style.RESET)
|
||||||
|
|
||||||
print('\nEnter new QSO details below:\n')
|
print ('%s%sEnter new QSO details below%s\n' % (style.UNDERLINED, hlcol, style.RESET))
|
||||||
|
|
||||||
qso_ok = False
|
qso_ok = False
|
||||||
qso = None
|
qso = None
|
||||||
@ -325,10 +352,12 @@ if __name__ == '__main__':
|
|||||||
while not qso_ok:
|
while not qso_ok:
|
||||||
# query QSO details from thbe user
|
# query QSO details from thbe user
|
||||||
qso = queryQSOData(qso)
|
qso = queryQSOData(qso)
|
||||||
print(qso)
|
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(tablecol)
|
||||||
print(tab)
|
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 askUser("Is this correct?"):
|
if askUser("Is this correct?"):
|
||||||
qso_ok = sendQSO(qso)
|
qso_ok = sendQSO(qso)
|
||||||
@ -353,4 +382,6 @@ if __name__ == '__main__':
|
|||||||
# quit the application
|
# quit the application
|
||||||
keeponlogging = False
|
keeponlogging = False
|
||||||
|
|
||||||
print("\nBye, bye!")
|
print(inputcol)
|
||||||
|
print("Bye, bye!")
|
||||||
|
print(style.RESET)
|
||||||
|
Loading…
Reference in New Issue
Block a user