def test_calculate_heading_longpath_edge_cases(self):

        assert abs(calculate_heading_longpath("JN48QM", "JN48QM") - 180 ) < 1
Esempio n. 2
0
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_calculate_heading_longpath(self):

        assert abs(calculate_heading_longpath("JN48QM", "FN44AB") - 118) < 1
        assert abs(calculate_heading_longpath("FN44AB", "JN48QM") - 234) < 1
        assert abs(calculate_heading_longpath("JN48QM", "QF67BF") - 254) < 1
        assert abs(calculate_heading_longpath("QF67BF", "JN48QM") - 130) < 1
Esempio n. 4
0
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="")
    print(fg('dark_sea_green_3b') + "%.1f°" % location.longitude, end="")
    print(fg('#884444') + attr('bold') + ' Grid square: ', end="")
    print(fg('dark_sea_green_3b') + maidenhead)
    print()