def test_copy_data_in_redis_2(self, fixCountryFile): lib = LookupLib(lookuptype="redis", redis_prefix="CF", redis_instance=r) fixCountryFile.copy_data_in_redis("CF", r) assert lib.lookup_callsign("3D2RI") == fixCountryFile.lookup_callsign( "3D2RI") assert lib.lookup_prefix("DH") == fixCountryFile.lookup_prefix("DH")
def locatehams(cs): lu = LookupLib(lookuptype='countryfile', filename='cty.plist') ci = Callinfo(lu) loc = [ci.get_all(c) for c in cs] return loc
def GetCallSignInfo(callsign): callsign_dict = {} #check if callsign is in file # use it #otherwise use website then write it to file my_lookuplib = LookupLib(lookuptype="qrz", username=apiusername, pwd=apipassword) cic = Callinfo(my_lookuplib) #if cic.is_valid_callsign(callsign): print('making api request') url = 'http://xmldata.qrz.com/xml/current/?s='+apikey+';callsign='+callsign response = requests.get(url) link='{http://xmldata.qrz.com}' root = ElementTree.fromstring(response.content) contact_dict = {} for child in root: if(child.tag == link+'Callsign'): for item in child: itemname = item.tag.replace(link,'') contact_dict[itemname] = item.text callsign_dict[callsign] = contact_dict
def GetCallSignInfo(callsign): callsign_dict = {} with open('contacts.json', 'r') as infile: try: callsign_dict = json.load(infile) if callsign in callsign_dict: return (callsign_dict[callsign]) except ValueError: print('empty dict') callsign_dict = {} #check if callsign is in file # use it #otherwise use website then write it to file my_lookuplib = LookupLib(lookuptype="qrz", username=apiusername, pwd=apipassword) cic = Callinfo(my_lookuplib) #if cic.is_valid_callsign(callsign): url = 'http://xmldata.qrz.com/xml/current/?s=' + apikey + ';callsign=' + callsign response = requests.get(url) link = '{http://xmldata.qrz.com}' root = ElementTree.fromstring(response.content) contact_dict = {} for child in root: if (child.tag == link + 'Callsign'): for item in child: itemname = item.tag.replace(link, '') contact_dict[itemname] = item.text callsign_dict[callsign] = contact_dict with open('contacts.json', 'w') as outfile: json.dump(callsign_dict, outfile) return (callsign_dict[callsign])
#!/usr/bin/python3 #cat /home/dk9mbs/wsprspots-2019-02.csv | grep DK9MBS | ./import.py --hook "/bin/bash /tmp/hook.sh" -q 2> /tmp/test.log import sys from datetime import datetime import argparse import os from pyhamtools import LookupLib, Callinfo from pyhamtools.frequency import freq_to_band from pyhamtools.consts import LookupConventions as const my_lookuplib = LookupLib(lookuptype="countryfile") class Reader: def __init__(self, file, inithook=False, linehook=False, verbose=False): self._file = file self.linehook = linehook self.inithook = inithook self.verbose = verbose def read(self): for line in self._file: line = line.replace('\r\n', "") line = line.replace('\n', "") line = line.replace('\r', "") values = line.split(",") wsprLine = WsprLine(line, self.linehook, self.verbose) newLine = wsprLine.getConvertedLine()
def test_copy_data_in_redis_2(self, fixCountryFile): lib = LookupLib(lookuptype="redis", redis_prefix="CF", redis_instance=r) fixCountryFile.copy_data_in_redis("CF", r) assert lib.lookup_callsign("3D2RI") == fixCountryFile.lookup_callsign("3D2RI") assert lib.lookup_prefix("DH") == fixCountryFile.lookup_prefix("DH")
def fixClublogXML(request, fixApiKey): Lib = LookupLib("clublogxml", fixApiKey) return (Lib)
def fixClublogApi(request, fixApiKey): Lib = LookupLib("clublogapi", fixApiKey) return (Lib)
def fixGeneralApi(request, fixApiKey): """Fixture returning all possible instances of LookupLib""" Lib = LookupLib(request.param, fixApiKey) # pytest.skip("better later") return (Lib)
def fix_qrz(): return LookupLib(lookuptype="qrz", username=QRZ_USERNAME, pwd=QRZ_PWD)
def fix_redis(): import redis return LookupLib(lookuptype="redis", redis_instance=redis.Redis(), redis_prefix="clx")
def fix_callinfo(request, fixApiKey): lib = LookupLib(request.param, fixApiKey) callinfo = Callinfo(lib) return (callinfo)
def fixCountryFile(request): Lib = LookupLib("countryfile") return (Lib)
async def qrzLookup(origcall, config): '''Lookup call @QRZ''' my_lookuplib = LookupLib(lookuptype="qrz", username=config['qrz.com']['username'], pwd=config['qrz.com']['password']) cic = Callinfo(my_lookuplib) origcall = origcall.upper() try: call = cic.get_homecall(origcall) lookup = await qrzRedisLookup(call) except ValueError: callsign = None lookup = {} #dict() print("Not Found") return {'origcallsign': origcall, 'callsign': callsign} if lookup is False: try: lookup = cic.get_all(call) callsign = lookup['callsign'] redis.set('qrz' + call.upper(), json.dumps(lookup, default=str)) redis.expire('qrz' + call.upper(), 2629743000) redis.sadd('qrzCALLS', call.upper()) calls.append(call.upper()) except ValueError: callsign = None lookup = {} #dict() print("Not Found") return {'origcallsign': origcall, 'callsign': callsign} except KeyError: callsign = call lookup = {} #dict() print("Not Found") return {'origcallsign': origcall, 'callsign': callsign} else: callsign = lookup['callsign'] if callsign and 'aliases' in lookup: print( fg('blue') + '-=' + fg('turquoise_4') + attr('bold') + callsign + attr('reset') + fg('blue') + '=-' + attr('reset') + " (" + ','.join(lookup['aliases']) + ')') else: print( fg('blue') + '-=' + fg('turquoise_4') + attr('bold') + callsign + fg('blue') + '=-') print(fg('#884444') + attr('bold') + 'QTH: ', end="") await dictLookupAndPrint(lookup, '#a4a24f', 'fname', False) await dictLookupAndPrint(lookup, '#a4a24f', 'name', False, ", ") await dictLookupAndPrint(lookup, 'navajo_white_3', 'addr1', False, ", ") await dictLookupAndPrint(lookup, 'navajo_white_3', 'zipcode', False) await dictLookupAndPrint(lookup, 'navajo_white_3', 'addr2', False, ", ") await dictLookupAndPrint(lookup, 'navajo_white_3', 'country') print(fg('#884444') + attr('bold') + 'Grid square: ', end="") await dictLookupAndPrint(lookup, 'dark_sea_green_3b', 'locator', False) print(fg('#884444') + attr('bold') + 'Latitude: ', end="") latitude = await dictLookupAndPrint(lookup, 'dark_sea_green_3b', 'latitude', False) print(fg('#884444') + attr('bold') + 'Longitude: ', end="") longitude = await dictLookupAndPrint(lookup, 'dark_sea_green_3b', 'longitude') print(fg('#884444') + attr('bold') + 'CCode: ', end="") await dictLookupAndPrint(lookup, 'dark_sea_green_3b', 'ccode', False) print(fg('#884444') + attr('bold') + 'CQZone: ', end="") await dictLookupAndPrint(lookup, 'dark_sea_green_3b', 'cqz', False) print(fg('#884444') + attr('bold') + 'ITUZone: ', end="") await dictLookupAndPrint(lookup, 'dark_sea_green_3b', 'ituz') print(fg('#884444') + attr('bold') + 'QSL: ', end="") await dictLookupAndPrint(lookup, 'navajo_white_3', 'qslmgr', False) print(fg('#884444') + attr('bold') + 'eQSL: ', end="") await dictLookupAndPrint(lookup, 'navajo_white_3', 'eqsl', False) print(fg('#884444') + attr('bold') + 'lotw: ', end="") await dictLookupAndPrint(lookup, 'navajo_white_3', 'lotw') print(fg('#884444') + attr('bold') + 'E-Mail: ', end="") email = await dictLookupAndPrint(lookup, 'navajo_white_3', 'email', True) locator1 = latlong_to_locator(cfg['qth']['latitude'], cfg['qth']['longitude']) locator2 = latlong_to_locator(latitude, longitude) heading = calculate_heading(locator1, locator2) longpath = calculate_heading_longpath(locator1, locator2) print(fg('#884444') + attr('bold') + 'Heading: ', end="") print(fg('navajo_white_3') + "%.1f°" % heading, end="") print(fg('#884444') + attr('bold') + ' Longpath: ', end="") print(fg('navajo_white_3') + "%.1f°" % longpath, end="") print(attr('reset')) return { 'origcallsign': origcall, 'callsign': callsign, 'email': email, 'latitude': latitude, 'longitude': longitude, 'heading': heading, 'longpath': longpath }
help="filename of ALL_WSPR.TXT-file", default='ALL_WSPR.TXT') args = parser.parse_args() try: f = open(args.fi, "r") except (IOError, OSError): print("Error: Cannot open file {} for reading!\n".format(args.fi)) exit(1) else: try: wspr_no = sum(1 for line in f) # load callsign checker my_lookuplib = LookupLib(lookuptype="clublogxml", filename=args.file_clublog) cic = Callinfo(my_lookuplib) f.seek(0) i = 1 for in_str in f: if args.reporter_comment: comment = args.reporter_comment else: comment = '' json_body = wspr_to_json(in_str, args.reporter, args.reporter_locator, comment) curl_str = json_curl_str(json_body) if (cic.is_valid_callsign(json_body[0]['tags']['call'])): print(curl_str) i = i + 1