This class is a wrapper for the following three Amateur Radio databases:
It’s aim is to provide a homogeneous interface to different databases.
Typically an instance of this class is injected as a dependency in the Callinfo class, but it can also be used directly.
Even the interface is the same for all lookup sources, the returning data can be different. The documentation of the various methods provide more detail.
By default, LookupLib requires an Internet connection to download the libraries or perform the lookup against the Clublog API.
The entire lookup data can also be copied into Redis, which an extremely fast in-memory Key/Value store. A LookupLib object can be instanciated to perform then all lookups in Redis, instead processing and loading the data from Internet / File. This saves some time and allows several instances of LookupLib to query the same data concurrently.
| Parameters: |
|
|---|
Copy the complete lookup data into redis. Old data will be overwritten.
| Parameters: |
|
|---|---|
| Returns: | returns True when the data has been copied successfully into Redis |
| Return type: | bool |
Example
Copy the entire lookup data from the Country-files.com PLIST File into Redis. This example requires a running instance of Redis, as well the python Redis connector (pip install redis-py).
>>> from pyhamtools import LookupLib
>>> import redis
>>> r = redis.Redis()
>>> my_lookuplib = LookupLib(lookuptype="countryfile")
>>> print my_lookuplib.copy_data_in_redis(redis_prefix="CF", redis_instance=r)
True
Now let’s create an instance of LookupLib, using Redis to query the data
>>> from pyhamtools import LookupLib
>>> import redis
>>> r = redis.Redis()
>>> my_lookuplib = LookupLib(lookuptype="countryfile", redis_instance=r, redis_prefix="CF")
>>> my_lookuplib.lookup_callsign("3D2RI")
{
u'adif': 460,
u'continent': 'OC',
u'country': 'Rotuma Island',
u'cqz': 32,
u'ituz': 56,
u'latitude': -12.48,
u'longitude': -177.08
}
Note
This method is available for the following lookup type
Returns True if an operations is known as invalid
| Parameters: |
|
|---|---|
| Returns: | True if a record exists for this callsign (at the given time) |
| Return type: | bool |
| Raises: |
|
Example
The following code checks the Clublog XML database if the operation is valid for two dates.
>>> from pyhamtools import LookupLib
>>> from datetime import datetime
>>> import pytz
>>> my_lookuplib = LookupLib(lookuptype="clublogxml", apikey="myapikey")
>>> print my_lookuplib.is_invalid_operation("5W1CFN")
True
>>> try:
>>> timestamp = datetime(year=2012, month=1, day=31).replace(tzinfo=pytz.UTC)
>>> my_lookuplib.is_invalid_operation("5W1CFN", timestamp)
>>> except KeyError:
>>> print "Seems to be invalid operation before 31.1.2012"
Seems to be an invalid operation before 31.1.2012
Note
This method is available for
Returns lookup data if an exception exists for a callsign
| Parameters: |
|
|---|---|
| Returns: | Dictionary containing the country specific data of the callsign |
| Return type: | dict |
| Raises: |
|
Example
The following code queries the the online Clublog API for the callsign “VK9XO” on a specific date.
>>> from pyhamtools import LookupLib
>>> from datetime import datetime
>>> import pytz
>>> my_lookuplib = LookupLib(lookuptype="clublogapi", apikey="myapikey")
>>> timestamp = datetime(year=1962, month=7, day=7, tzinfo=pytz.UTC)
>>> print my_lookuplib.lookup_callsign("VK9XO", timestamp)
{
'country': 'CHRISTMAS ISLAND',
'longitude': -105.7,
'cqz': 29,
'adif': 35,
'latitude': -10.5,
'continent': 'OC'
}
Note
This method is available for
Returns lookup data of an ADIF Entity
| Parameters: | entity (int) – ADIF identifier of country |
|---|---|
| Returns: | Dictionary containing the country specific data |
| Return type: | dict |
| Raises: | KeyError – No matching entity found |
Example
The following code queries the the Clublog XML database for the ADIF entity Turkmenistan, which has the id 273.
>>> from pyhamtools import LookupLib
>>> my_lookuplib = LookupLib(lookuptype="clublogapi", apikey="myapikey")
>>> print my_lookuplib.lookup_entity(273)
{
'deleted': False,
'country': 'TURKMENISTAN',
'longitude': -58.4,
'cqz': 17,
'prefix': 'EZ',
'latitude': 38.0,
'continent': 'AS'
}
Note
This method is available for the following lookup type
Returns lookup data of a Prefix
| Parameters: |
|
|---|---|
| Returns: | Dictionary containing the country specific data of the Prefix |
| Return type: | dict |
| Raises: |
|
Example
The following code shows how to obtain the information for the prefix “DH” from the countryfile.com database (default database).
>>> from pyhamtools import LookupLib
>>> myLookupLib = LookupLib()
>>> print myLookupLib.lookup_prefix("DH")
{
'adif': 230,
'country': 'Fed. Rep. of Germany',
'longitude': -10.0,
'cqz': 14,
'ituz': 28,
'latitude': 51.0,
'continent': 'EU'
}
Note
This method is available for
Returns a CQ Zone if an exception exists for the given callsign
Args: callsign (string): Amateur radio callsign timestamp (datetime, optional): datetime in UTC (tzinfo=pytz.UTC)
| Returns: | Value of the the CQ Zone exception which exists for this callsign (at the given time) |
|---|---|
| Return type: | int |
| Raises: |
|
Example
The following code checks the Clublog XML database if a CQ Zone exception exists for the callsign DP0GVN.
>>> from pyhamtools import LookupLib
>>> my_lookuplib = LookupLib(lookuptype="clublogxml", apikey="myapikey")
>>> print my_lookuplib.lookup_zone_exception("DP0GVN")
38
The prefix “DP” It is assigned to Germany, but the station is located in Antarctica, and therefore in CQ Zone 38
Note
This method is available for