XML service now queried via POST requests - thanks /u/AJamesBrown!

moved URLs from config to code since the code might be API version dependent
This commit is contained in:
Michael Clemens 2021-05-26 07:07:52 +02:00
parent 9b5309b9f0
commit 235275eb75
2 changed files with 20 additions and 9 deletions

View File

@ -17,9 +17,6 @@ qrz_pass = q1w2e3r4t5z6u7i8o9
# OPTIONAL configuration seetings
# You shouldn't need to change this URL except when QRZ.com changes it some day
api_url = https://logbook.qrz.com/api
# The fields you want to pull from the XML service when querying a call sign
xml_fields = ("call", "band", "mode", "qso_date", "time_on", "rst_sent", "rst_rcvd", "comment")

View File

@ -54,6 +54,10 @@ from colored import fore, back, style
config = configparser.ConfigParser()
config.read('config.ini')
# QRZ.com URLs
xml_url = "https://xmldata.QRZ.com/xml/current/"
api_url = "https://logbook.qrz.com/api"
# headers for all POST requests
headers = CaseInsensitiveDict()
headers["Content-Type"] = "application/x-www-form-urlencoded"
@ -109,12 +113,16 @@ bandfreqs = {
def get_session():
global session
global session_key
xml_auth_url = '''https://xmldata.QRZ.com/xml/current/?username={0}&password={1}'''.format(
config['qrzlogger']['qrz_user'],config['qrzlogger']['qrz_pass'])
data = {
'username' : config['qrzlogger']['qrz_user'],
'password' : config['qrzlogger']['qrz_pass']
}
try:
session = requests.Session()
session.verify = bool(os.getenv('SSL_VERIFY', True))
r = session.get(xml_auth_url)
r = session.post(xml_url, data=data)
if r.status_code == 200:
raw_session = xmltodict.parse(r.content)
session_key = raw_session.get('QRZDatabase').get('Session').get('Key')
@ -136,7 +144,7 @@ def get_session():
# and returns the response
def sendRequest(post_data):
try:
resp = requests.post(config['qrzlogger']['api_url'], headers=headers, data=post_data)
resp = requests.post(api_url, headers=headers, data=post_data)
if resp.status_code == 200:
str_resp = resp.content.decode("utf-8")
response = urllib.parse.unquote(str_resp)
@ -166,9 +174,15 @@ def getCallData(call):
global session
global session_key
data = {
's' : session_key,
'callsign' : call
}
try:
xml_url = """https://xmldata.QRZ.com/xml/current/?s={0}&callsign={1}""" .format(session_key, call)
r = session.get(xml_url)
session = requests.Session()
session.verify = bool(os.getenv('SSL_VERIFY', True))
r = session.post(xml_url, data=data)
raw = xmltodict.parse(r.content).get('QRZDatabase')
calldata = raw.get('Callsign')
if calldata: