Callinfo

class pyhamtools.callinfo.Callinfo(lookuplib, logger=None)

The purpose of this class is to return data (country, latitude, longitude, CQ Zone...etc) for an Amateur Radio callsign. The class can be used with any lookup database, provided through an Instance of LookupLib. An instance of Lookuplib has to be injected on object construction.

Parameters:
  • lookuplib (LookupLib) – instance of LookupLib
  • logger (logging.getLogger(__name__), optional) – Python logger
get_adif_id(callsign, timestamp=datetime.datetime(2014, 6, 15, 8, 12, 7, 27244, tzinfo=<UTC>))

Returns ADIF id of a callsign’s country

Parameters:
  • callsign (str) – Amateur Radio callsign
  • timestamp (datetime, optional) – datetime in UTC (tzinfo=pytz.UTC)
Returns:

containing the country ADIF id

Return type:

int

Raises:

KeyError – No Country found for callsign

get_all(callsign, timestamp=datetime.datetime(2014, 6, 15, 8, 12, 7, 27244, tzinfo=<UTC>))

Lookup a callsign and return all data available from the underlying database

Parameters:
  • callsign (str) – Amateur Radio callsign
  • timestamp (datetime, optional) – datetime in UTC (tzinfo=pytz.UTC)
Returns:

Dictionary containing the callsign specific data

Return type:

dict

Raises:

KeyError – Callsign could not be identified

Example

The following code returns all available information from the country-files.com database for the callsign “DH1TW”

>>> from pyhamtools import LookupLib, Callinfo
>>> my_lookuplib = LookupLib(lookuptype="countryfile")
>>> cic = Callinfo(my_lookuplib)
>>> cic.get_all("DH1TW")
{
    'country': 'Fed. Rep. of Germany',
    'adif': 230,
    'continent': 'EU',
    'latitude': 51.0,
    'longitude': -10.0,
    'cqz': 14,
    'ituz': 28
}

Note

The content of the returned data depends entirely on the injected LookupLib (and the used database). While the country-files.com provides for example the ITU Zone, Clublog doesn’t. Consequently, the item “ituz” would be missing with Clublog (API or XML) LookupLib.

get_continent(callsign, timestamp=datetime.datetime(2014, 6, 15, 8, 12, 7, 27244, tzinfo=<UTC>))

Returns the continent Identifier of a callsign

Parameters:
  • callsign (str) – Amateur Radio callsign
  • timestamp (datetime, optional) – datetime in UTC (tzinfo=pytz.UTC)
Returns:

continent identified

Return type:

str

Raises:

KeyError – No Continent found for callsign

Note

The following continent identifiers are used:

  • EU: Europe
  • NA: North America
  • SA: South America
  • AS: Asia
  • AF: Africa
  • OC: Oceania
  • AN: Antarctica
get_country_name(callsign, timestamp=datetime.datetime(2014, 6, 15, 8, 12, 7, 27244, tzinfo=<UTC>))

Returns the country name where the callsign is located

Parameters:
  • callsign (str) – Amateur Radio callsign
  • timestamp (datetime, optional) – datetime in UTC (tzinfo=pytz.UTC)
Returns:

name of the Country

Return type:

str

Raises:

KeyError – No Country found for callsign

Note

Don’t rely on the country name when working with several instances of py:class:Callinfo. Clublog and Country-files.org use slightly different names for countries. Example:

  • Country-files.com: “Fed. Rep. of Germany”
  • Clublog: “FEDERAL REPUBLIC OF GERMANY”
get_cqz(callsign, timestamp=datetime.datetime(2014, 6, 15, 8, 12, 7, 27244, tzinfo=<UTC>))

Returns CQ Zone of a callsign

Parameters:
  • callsign (str) – Amateur Radio callsign
  • timestamp (datetime, optional) – datetime in UTC (tzinfo=pytz.UTC)
Returns:

containing the callsign’s CQ Zone

Return type:

int

Raises:

KeyError – no CQ Zone found for callsign

static get_homecall(callsign)

Strips off country prefixes (HC2/**DH1TW) and activity suffixes (DH1TW/P**).

Parameters:callsign (str) – Amateur Radio callsign
Returns:callsign without country/activity pre/suffixes
Return type:str
Raises:ValueError – No callsign found in string

Example

The following code retrieves the home call for “HC2/DH1TW/P”

>>> from pyhamtools import LookupLib, Callinfo
>>> my_lookuplib = LookupLib(lookuptype="countryfile")
>>> cic = Callinfo(my_lookuplib)
>>> cic.get_homecall("HC2/DH1TW/P")
DH1TW
get_ituz(callsign, timestamp=datetime.datetime(2014, 6, 15, 8, 12, 7, 27244, tzinfo=<UTC>))

Returns ITU Zone of a callsign

Parameters:
  • callsign (str) – Amateur Radio callsign
  • timestamp (datetime, optional) – datetime in UTC (tzinfo=pytz.UTC)
Returns:

containing the callsign’s CQ Zone

Return type:

int

Raises:

KeyError – No ITU Zone found for callsign

Note

Currently, only Country-files.com lookup database contains ITU Zones

get_lat_long(callsign, timestamp=datetime.datetime(2014, 6, 15, 8, 12, 7, 27244, tzinfo=<UTC>))

Returns Latitude and Longitude for a callsign

Parameters:
  • callsign (str) – Amateur Radio callsign
  • timestamp (datetime, optional) – datetime in UTC (tzinfo=pytz.UTC)
Returns:

Containing Latitude and Longitude

Return type:

dict

Raises:

KeyError – No data found for callsign

Example

The following code returns Latitude & Longitude for “DH1TW”

>>> from pyhamtools import LookupLib, Callinfo
>>> my_lookuplib = LookupLib(lookuptype="countryfile")
>>> cic = Callinfo(my_lookuplib)
>>> cic.get_lat_long("DH1TW")
{
    'latitude': 51.0,
    'longitude': -10.0
}

Note

Unfortunately, in most cases the returned Latitude and Longitude are not very precise. Clublog and Country-files.com use the country’s capital coordinates in most cases, if no dedicated entry in the database exists.

is_valid_callsign(callsign, timestamp=datetime.datetime(2014, 6, 15, 8, 12, 7, 27244, tzinfo=<UTC>))

Checks if a callsign is valid

Parameters:
  • callsign (str) – Amateur Radio callsign
  • timestamp (datetime, optional) – datetime in UTC (tzinfo=pytz.UTC)
Returns:

True / False

Return type:

bool

Example

The following checks if “DH1TW” is a valid callsign

>>> from pyhamtools import LookupLib, Callinfo
>>> my_lookuplib = LookupLib(lookuptype="countryfile")
>>> cic = Callinfo(my_lookuplib)
>>> cic.is_valid_callsign("DH1TW")
True

Previous topic

utils

Next topic

LookupLib

This Page