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)
import os import datetime import zipfile import urllib.request, urllib.error, urllib.parse # Used to automatically download data files from the web. from collections import OrderedDict import numpy as np import pandas as pd import tqdm import mysql.connector #from pyporktools import qrz from qrz import QRZ #sudo pip3 install pyQRZ qrz = QRZ(cfg='./qrz_settings.cfg') from .data import clean_call from . import geopack Re = 6371 def rbn_csv_to_df(csv_file): """ Reads a RBN CSV into a dataframe. """ df = pd.read_csv(csv_file, parse_dates=[0]) return df def get_df(csv_file, qth_locator=None):
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}")
def main(): program_name = 'qsomysql' program_version = '1.2' qrz = QRZ(cfg='./qrz.ini') config = configparser.ConfigParser() config.read(['qsoviz.ini', 'qrz.ini']) use_n3fjp_mdb = config['general'].getboolean('use_n3fjp_mdb') reset_mysql_db = config['general'].getboolean('reset_mysql_db') db_user = config['mysql']['db_user'] db_password = config['mysql']['db_password'] db_name = config['mysql']['db_name'] logging.basicConfig(filename='/home/qsoviz/qsomysql.log', level=logging.INFO, format='%(asctime)s %(message)s') logging.info('%s %s: Run started', program_name, program_version) states_fp = open('states.json', 'r') states_coords = json.load(states_fp) states_fp.close() mysql_cnx = mysql.connector.connect(user=db_user, password=db_password, database=db_name) mysql_cursor = mysql_cnx.cursor() if reset_mysql_db: mysql_cursor.execute("DELETE FROM aarc_fd") mysql_cnx.commit() add_qso = ( "INSERT INTO aarc_fd " "(datetime_on, callsign, n3fjp_modecontest, band, state, arrl_sect, country, " + "n3fjp_initials, operator, class, computer_name, latitude, longitude, geohash) " "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)") query_qso = "SELECT datetime_on, callsign FROM aarc_fd WHERE datetime_on = %s AND callsign = %s" logfile_filename = newest_file('/home/qsoviz/logfiles') records_added = 0 if use_n3fjp_mdb: fields = [ 'fldCall', 'fldModeContest', 'fldBand', 'fldState', 'fldSection', 'fldCountryWorked', 'fldInitials', 'fldOperator', 'fldClass', 'fldComputerName' ] df = mdb.read_table(logfile_filename, 'tblContacts') for idx, row in df.iterrows(): fldDateStr = row.loc['fldDateStr'] fldTimeOnStr = row.loc['fldTimeOnStr'] year, month, day = fldDateStr.split('/') hour, minute, second = fldTimeOnStr.split(':') a_datetime_on = datetime(int(year), int(month), int(day), hour=int(hour), minute=int(minute), second=int(second), tzinfo=timezone.utc) a_callsign = row.loc['fldCall'] query_qso_data = (a_datetime_on, a_callsign) mysql_cursor.execute(query_qso, query_qso_data) result = mysql_cursor.fetchall() if len(result) == 0: add_qso_data = [a_datetime_on] for field in fields: temp = row.loc[field] if temp != temp: temp = '' temp = temp.upper() add_qso_data.append(temp) a_latitude, a_longitude, a_geohash = geo_info( qrz, add_qso_data[1], add_qso_data[4], states_coords) add_qso_data.append(a_latitude) add_qso_data.append(a_longitude) add_qso_data.append(a_geohash) add_qso_data = tuple(add_qso_data) mysql_cursor.execute(add_qso, add_qso_data) mysql_cnx.commit() records_added = records_added + 1 else: adif_fp = open(logfile_filename, 'r') qsos = ADIReader(adif_fp) for qso in qsos: a_datetime_on = qso['datetime_on'] fldCall = qso['call'].upper() query_qso_data = (a_datetime_on, fldCall) result = mysql_cursor(query_qso, query_qso_data) if not result: fldModeContest = qso.get('mode', 'NONE').upper() fldBand = qso.get('band', 'NONE').upper() fldState = qso.get('state', 'NONE').upper() fldSection = qso.get('arrl_sect', 'NONE').upper() fldCountryWorked = qso.get('country', 'NONE').upper() fldInitials = qso.get('app_n3fjp_initials', 'NONE').upper() fldOperator = qso.get('operator', 'NONE').upper() fldClass = qso.get('class', 'NONE').upper() fldComputerName = qso.get('n3fjp_stationid', 'NONE').upper() a_latitude, a_longitude, a_geohash = geo_info( qrz, fldCall, fldState, states_coords) add_qso_data = (a_datetime_on, fldCall, fldModeContest, fldBand, fldState, fldSection, fldCountryWorked, fldInitials, fldOperator, fldClass, fldComputerName, a_latitude, a_longitude, a_geohash) mysql_cursor.execute(add_qso, add_qso_data) mysql_cnx.commit() records_added = records_added + 1 if not use_n3fjp_mdb: adif_fp.close() mysql_cursor.close() mysql_cnx.close() logging.info('%s %s: records_added = %s', program_name, program_version, records_added) logging.info('%s %s: Run ended', program_name, program_version)