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 test_redis_lookup(self, fixClublogXML, fix_redis): timestamp = datetime(year=2016, month=1, day=20, tzinfo=UTC) ci = Callinfo(fix_redis) assert ci.get_all( "VP8STI", timestamp) == response_Exception_VP8STI_with_start_and_stop_date assert ci.get_all("tu5pct") == response_TU5PCT
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])
def __init__(self, line, linehook="", verbose=False): self._line = line self._fields = {} self.linehook = linehook self.verbose = verbose values = self._line.split(",") reporter = { 'latitude': 0, 'ituz': 0, 'country': 'NA', 'cqz': 0, 'continent': 'NA', 'adif': 0, 'longitude': 0 } callsign = { 'latitude': 0, 'ituz': 0, 'country': 'NA', 'cqz': 0, 'continent': 'NA', 'adif': 0, 'longitude': 0 } band = {'band': 0, 'mode': 'NA'} cic = Callinfo(my_lookuplib) try: reporter = cic.get_all(values[2]) if self.verbose: sys.stderr.write("Decoded reporter => " + values[2] + "\n") except: sys.stderr.write("Error decoding reporter => " + values[2] + "\n") try: callsign = cic.get_all(values[6]) if self.verbose: sys.stderr.write("Decoded callsign => " + values[6] + "\n") except: sys.stderr.write("Error decoding callsign => " + values[6] + "\n") try: band = freq_to_band(float(values[5]) * 1000) except: sys.stderr.write("Error decoding freq => " + values[5] + "\n") self._fields[0] = WsprField('spotid', values[0]) self._fields[1] = WsprField( 'timestamp', datetime.utcfromtimestamp(int( values[1])).strftime('%Y-%m-%d %H:%M:%S')) self._fields[2] = WsprField('reporter', values[2]) self._fields[3] = WsprField('reportergrid', values[3]) self._fields[4] = WsprField('snr', values[4]) self._fields[5] = WsprField('freq', values[5]) self._fields[6] = WsprField('callsign', values[6]) self._fields[7] = WsprField('grid', values[7]) self._fields[8] = WsprField('power', values[8]) self._fields[9] = WsprField('drift', values[9]) self._fields[10] = WsprField('distance', values[10]) self._fields[11] = WsprField('azimuth', values[11]) self._fields[12] = WsprField('band', band['band']) self._fields[13] = WsprField('version', values[13]) self._fields[14] = WsprField('code', values[14]) self._fields[15] = WsprField( 'date', datetime.utcfromtimestamp(int(values[1])).strftime('%Y-%m-%d')) self._fields[16] = WsprField( 'time', datetime.utcfromtimestamp(int(values[1])).strftime('%H:%M:%S')) self._fields[17] = WsprField('reporter_latitude', reporter['latitude']) self._fields[18] = WsprField('reporter_longitude', reporter['longitude']) self._fields[19] = WsprField('reporter_ituz', reporter['ituz']) self._fields[20] = WsprField('reporter_country', reporter['country']) self._fields[21] = WsprField('reporter_cqz', reporter['cqz']) self._fields[22] = WsprField('reporter_continent', reporter['continent']) self._fields[23] = WsprField('reporter_adif', reporter['adif']) self._fields[24] = WsprField('callsign_latitude', callsign['latitude']) self._fields[25] = WsprField('callsign_longitude', callsign['longitude']) self._fields[26] = WsprField('callsign_ituz', callsign['ituz']) self._fields[27] = WsprField('callsign_country', callsign['country']) self._fields[28] = WsprField('callsign_cqz', callsign['cqz']) self._fields[29] = WsprField('callsign_continent', callsign['continent']) self._fields[30] = WsprField('callsign_adif', callsign['adif']) self._fields[31] = WsprField('bandmode', band['mode']) if self.linehook: self._execHook() else: sys.stderr.write("no hook script defined!\n")
#!/usr/bin/python3 from pyhamtools import LookupLib, Callinfo my_lookuplib = LookupLib(lookuptype="countryfile") cic = Callinfo(my_lookuplib) print(cic.get_all("DK9MBS"))
def fix_callinfo(request, fixApiKey): lib = LookupLib(request.param, fixApiKey) callinfo = Callinfo(lib) return (callinfo)
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 }
def test_redis_lookup(self, fixClublogXML, fix_redis): timestamp = datetime(year=2016, month=1, day=20, tzinfo=UTC) ci = Callinfo(fix_redis) assert ci.get_all("VP8STI", timestamp) == response_Exception_VP8STI_with_start_and_stop_date
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 finally:
return qso if __name__ == "__main__": # instanciate a Importer object cabImporter = Importer() # parse the provided file qsos = cabImporter.parse("./k1ir.log") # I suggest to use ClublogXML instead. Clublog is the best lookupDB. # But you need an API key which you can request on the clublog website. print "loading country files... this might take 10-30s" my_lookuplib = LookupLib(lookuptype="countryfile") cic = Callinfo(my_lookuplib) for qso in qsos: try: qso.own_call_info = cic.get_all(qso.own_call) qso.partner_call_info = cic.get_all(qso.partner_call) except KeyError: print "unable to get infos for " + qso.own_call f = open("enriched_log.txt", "w") for qso in qsos: f.write(qso.export_string()) f.close()