def test_latlong_to_locator_invalid_characters(self): with pytest.raises(ValueError): latlong_to_locator("JN48QM", "test") with pytest.raises(ValueError): latlong_to_locator("", "")
def test_latlong_to_locator_invalid_characters(self): with pytest.raises(ValueError): latlong_to_locator("JN48QM", "test") with pytest.raises(ValueError): latlong_to_locator("", "")
def test_latlong_to_locator_invalid_characters(self): # throws ValueError in Python2 and TypeError in Python3 with pytest.raises(Exception): latlong_to_locator("JN48QM", "test") # throws ValueError in Python2 and TypeError in Python3 with pytest.raises(Exception): latlong_to_locator("", "")
def test_latlong_to_locator_invalid_characters(self): # throws ValueError in Python2 and TypeError in Python3 with pytest.raises(Exception): latlong_to_locator("JN48QM", "test") # throws ValueError in Python2 and TypeError in Python3 with pytest.raises(Exception): latlong_to_locator("", "")
def test_latlong_to_locator_out_of_boundry(self): with pytest.raises(ValueError): latlong_to_locator(-90, -180) with pytest.raises(ValueError): latlong_to_locator(90, 180) with pytest.raises(ValueError): latlong_to_locator(10000, 120000)
def test_latlong_to_locator_out_of_boundry(self): with pytest.raises(ValueError): latlong_to_locator(-90, -180) with pytest.raises(ValueError): latlong_to_locator(90, 180) with pytest.raises(ValueError): latlong_to_locator(10000, 120000)
def test_latlong_to_locator_edge_cases(self): assert latlong_to_locator(-89.97916, -179.95833) == "AA00AA" assert latlong_to_locator(89.97916, 179.9583) == "RR99XX"
def test_latlong_to_locator_normal_case(self): assert latlong_to_locator(48.52083, 9.3750000) == "JN48QM" assert latlong_to_locator(48.5, 9.0) == "JN48MM" #center of the square
for row in repeater_rows: count = count + 1 if count == 1: continue # Skip the header row fields = row.find_all('td') repeater = Repeater(fields[2].next_element.strip()) if repeater.callsign[0:2] == "GB": continue # we get these anyway from ukrepeater repeater.rx = fields[1].next_element.next_element.next_element.strip() repeater.tx = fields[1].next_element.next_element.next_element.next_element.next_element.next_element.next_element.strip() activation = re.sub("\/", "", fields[3].next_element.strip()) if activation == "Carrier": repeater.carrier = True elif activation == "1750Hz": repeater.burst = True else: repeater.ctcss = re.sub("Hz", "", activation) repeater.mode = "FM" repeater.town = fields[4].next_element.strip() location = geolocator.geocode(re.sub(",.*$", "", repeater.town) + ", Republic of Ireland", timeout=10) if location == None: continue # TODO need to get a better geocoding system, or actually pull out the ml repeater.lat = location.latitude repeater.lon = location.longitude repeater.locator = latlong_to_locator(repeater.lat, repeater.lon) time.sleep(2) repeater.source = "http://www.irts.ie/" print repeater repeater.update()
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_latlong_to_locator_edge_cases(self): assert latlong_to_locator(-89.97916, -179.95833) == "AA00AA" assert latlong_to_locator(89.97916, 179.9583) == "RR99XX"
def test_latlong_to_locator_normal_case(self): assert latlong_to_locator(48.52083, 9.3750000) == "JN48QM" assert latlong_to_locator(48.5, 9.0) == "JN48MM" #center of the square
# Prompt. 'message': '#884444', 'prompt': 'fg:#aa0022 bold' }) configdir = os.path.expanduser('~/.config/ham-tools') with open(configdir + '/config.yaml') as f: cfg = yaml.load(f, Loader=yaml.FullLoader) address = ' '.join(sys.argv[1:]) geolocator = Nominatim(user_agent="ON3URE_hamtools") try: location = geolocator.geocode(address) locator1 = latlong_to_locator(cfg['qth']['latitude'], cfg['qth']['longitude']) locator2 = latlong_to_locator(location.latitude, location.longitude) heading = calculate_heading(locator1, locator2) longpath = calculate_heading_longpath(locator1, locator2) maidenhead = mh.to_maiden(location.latitude, location.longitude) print( fg('blue') + '-=' + fg('turquoise_4') + attr('bold') + "QTE: Bearing lookup" + attr('reset') + fg('blue') + '=-' + attr('reset')) print(fg('#884444') + attr('bold') + 'Address: ', end="") print(fg('dark_sea_green_3b') + location.address) print(fg('#884444') + attr('bold') + 'Latitude: ', end="") print(fg('dark_sea_green_3b') + "%.1f°" % location.latitude, end="") print(fg('#884444') + attr('bold') + ' Longitude: ', end="")
rsgb_url = "http://www.rsgbdata.net/clubinfo/process.php?lat=55&lng=0&radius=900" rsgb_handle = urllib2.urlopen(rsgb_url) rsgb_xml = parse(rsgb_handle) rsgb_handle.close() geolocator = Nominatim() prog = re.compile("[2GM][A-Z]?[0-9][A-Z]+") for row in rsgb_xml.getElementsByTagName("marker"): c = Club(row.attributes['clubcall'].value) if c.callsign.startswith("RS"): continue # not a real callsign c.town = c.name = row.attributes['clubname'].value c.lat = row.attributes['lat'].value c.lon = row.attributes['lng'].value c.locator = latlong_to_locator(float(c.lat), float(c.lon)) address = geolocator.reverse((float(c.lat), float(c.lon))).address.split(", ") if len(address) < 4: c.town = address[1] else: c.town = address[2] contact = row.attributes['contact'].value keepers = prog.findall(contact) if len(keepers) != 0: c.keeper = keepers[0] c.source = "http://rsgb.org/" print c c.update() time.sleep(5)