def test_session_expire(self): qrz = QRZ() result = qrz.callsign("w7atc") self.assertEqual(result['fname'], 'ZEB M') qrz._session_key += "_test_invalid" result = qrz.callsign("w7atc") self.assertEqual(result['fname'], 'ZEB M')
def test_all(self): qrz = QRZ() result = qrz.callsign("w7atc") self.assertEqual(result['fname'], 'ZEB M') self.assertEqual(result['name'], 'PALMER') self.assertEqual(result['addr2'], 'Nampa') self.assertEqual(result['state'], 'ID') self.assertEqual(result['country'], 'United States')
#help='Specifies the path to the folder that contains the log files to summarize.') return parser.parse_args() def print_keys(key_names, query_result): """ Prints results and does not throw exception on queries like W1AW where fname key does not exist """ info = "" for key_name in key_names: if key_name in query_result: info += query_result[key_name] + " " print(info) if __name__ == '__main__': args = get_args() if (args.args.callsign): qrz = QRZ('./settings.cfg') result = qrz.callsign("w7atc") print_keys(['fname', 'name'], result) print_keys(['addr2', 'state'], result) print_keys(['country'], result) # Show all the data available from QRZ.com print('-' * 50) for dict_key, dict_value in sorted(result.items()): print(u'{0}: {1}'.format(dict_key, dict_value)) else: print('Give me a sign...')
from qrz import QRZ def print_keys(key_names, query_result): """ Prints results and does not throw exception on queries like W1AW where fname key does not exist """ info = "" for key_name in key_names: if key_name in query_result: info += query_result[key_name] + " " print info if __name__=='__main__': qrz = QRZ('./settings.cfg') result = qrz.callsign("w7atc") print_keys(['fname', 'name'], result) print_keys(['addr2', 'state'], result) print_keys(['country'], result) # Show all the data available from QRZ.com print '-' * 50 for dict_key, dict_value in sorted(result.items()): print u'{0}: {1}'.format(dict_key, dict_value)
def test_invalid_callsign(self): qrz = QRZ() # noinspection PyUnusedLocal with self.assertRaises(CallsignNotFound) as context: qrz.callsign("w7atcw7atc")
# Revision History: # # 20170113 - WSH - initial code # 20170121 - WSH - added better comments # 20170528 - WSH - ported to NetBeans from qrz import QRZ def print_keys(key_names, query_result): # define the print_keys function info = "" for key_name in key_names: if key_name in query_result: info += query_result[key_name] + " " print info # Open the log file for read access fhand = open('/home/ka1ssr/NetBeansProjects/LogLookup/DStarRepeater-2017-01-07.log') for line in fhand: key = line[42:45] # extract characters 42 through 45 if key == 'My:': callsign = line[46:52] # callsign is characters 46 through 52 qrz = QRZ('/home/ka1ssr/pyQRZ/settings.cfg') result = qrz.callsign(callsign) # pass callsign to qrz print callsign print_keys(['fname', 'name'], result) # print first & last name print_keys(['addr2', 'state'], result) # print City & State print_keys(['country'], result) # print country print '\n' # newline continue # grab the next line in the log file
#!/usr/bin/env python3 from qrz import QRZ, CallsignNotFound, QRZsessionNotFound import argparse qrz = QRZ('./settings.cfg') parser = argparse.ArgumentParser(prog='who-qrz', description='Callsign Lookup') parser.add_argument('callsign', help='The callsign you wish to lookup.') args = parser.parse_args() cs = vars(args)['callsign'] try: result = qrz.callsign(cs) print(f"{result['call']} - {result['fname']} {result['name']}") print(f"{result['addr2']}, {result['state']} {result['country']}") except CallsignNotFound as e: print(f"callsign {cs} not found") except QRZsessionNotFound as e: print( f"could not obtain session from qrz, check credentials config or environment vars" ) except Exception as e: print(f"Unknown error: {e}")