Giter Club home page Giter Club logo

pyhamtools's Introduction

pyhamtools

Build Status codecov PyPI version

Pyhamtools is a set of functions and classes for Amateur Radio purposes. Currently, the core part is the Callsign Lookup which decodes any amateur radio callsign string and provides the corresponding information (Country, DXCC entity, CQ Zone...etc). This basic functionality is needed for Logbooks, DX-Clusters or Log Checking. This and additional convenience features are provided for the following sources:

Currently,

Other modules include location-based calculations (e.g. distance, heading between Maidenhead locators) or frequency-based calculations (e.g. frequency to band).

References

This Library is used in production at the DXHeat.com DX Cluster, performing several thousand lookups and calculations per day.

Compatibility

Pyhamtools is compatible with Python >=3.6. We check compatibility on OSX, Windows, and Linux with the following Python versions:

  • Python 3.6 (will be deprecated in 2024)
  • Python 3.7 (will be deprecated in 2024)
  • Python 3.8
  • Python 3.9
  • Python 3.10
  • Python 3.11
  • Python 3.12
  • pypy3.7 (will be deprecated in 2024)
  • pypy3.8
  • pypy3.9
  • pypy3.10

The support for Python 2.7 and 3.5 has been deprecated at the end of 2023. The last version which supports Python 2.7 and Python 3.5 is 0.8.7.

Documentation

Check out the full documentation including the changelog at: pyhamtools.readthedocs.org

License

Pyhamtools is published under the permissive MIT License. You can find a good comparison of Open Source Software licenses, including the MIT license at choosealicense.com

Dependencies

Starting with version 0.8.0, libxml2-dev and libxslt-dev are required dependencies.

There is a good change that the libraries are already installed on your system. If not, you can install them with the package manager of your distro. For example on Debian / Ubuntu based distros the corresponding command is:

$ sudo apt-get install libxml2-dev libxslt-dev

You don't need to install these libraries manually on Windows / MacOS.

Installation

The easiest way to install pyhamtools is through the packet manager pip:

$ pip install pyhamtools

Christoph, @df7cb is kindly maintaining a Debian package as an alternative way to install pyhamtools:

$ sudo apt-get install pyhamtools

Example: How to use pyhamtools

>>> from pyhamtools.locator import calculate_heading
>>> calculate_heading("JN48QM", "QF67bf")
74.3136


>>> 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
    }

Testing

An extensive set of unit tests has been created for all Classes & Methods. To be able to perform all tests, you need a QRZ.com account and a Clublog API key.

pyhamtools rely on the pytest testing framework. To install it with all the needed dependencies run:

$ pip install -r requirements-pytest.txt

The QRZ.com credentials and the Clublog API key have to be set in the environment variables:

$ export CLUBLOG_APIKEY="<your API key>"
$ export QRZ_USERNAME="<your qrz.com username>"
$ export QRZ_PWD="<your qrz.com password>"

To perform the tests related to the redis key/value store, a Redis server has to be up & running.

$ sudo apt install redis-server
$ redis-server

To run the tests, simply execute:

$ pytest --cov pyhamtools

Generate the documentation

You can generate the documentation of pyhamtools with the following commands:

$ pip install -r requirements-docs.txt
$ cd docs
$ make html

pyhamtools's People

Contributors

devnulling avatar df7cb avatar dforsi avatar dh1tw avatar gitter-badger avatar kholia avatar kstrishock-omnivore avatar threeio avatar tmancill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyhamtools's Issues

Problems with RBx preffix.

Hello Tobi. Thanks for your amazing work with the library.

Recently I'm using the method "get_all" with ALL RBx preffix.

This is the ressult of the method:

>>> cic = Callinfo(my_lookuplib1)
>>> print(cic.get_all('rb4nb'))
{'country': 'INVALID'}
>>> print(cic.get_all('rb1aa'))
{'country': 'INVALID'}

Thanks in advance.

73 & DX!

Run tests without API keys, and without networking

Hi,
I'm working on getting pyhamtools into Debian because I'm using it for my logbook [1]. I have the packaging ready [2], but the testsuite is failing because I'm running without QRZ/clublog API keys (and I don't want to give these to the Debian buildd network). Also, we have the requirements that builds shouldn't be accessing the internet. Could we maybe have

  • a switch to disable all the networking tests at build time, including redis?
  • for a separate test stage, a switch to disable all tests that require a personalized API key, so we could still test the networking bits outside the buildds? I can probably get the redis tests working at this stage

Thanks,
Christoph DF7CB

[1] https://github.com/df7cb/df7cb-log
[2] https://salsa.debian.org/debian-hamradio-team/pyhamtools

I: pybuild base:217: cd /srv/projects/afu/pyhamtools/pyhamtools.git/.pybuild/cpython3_3.8/build; python3.8 -m pytest test
===================================== test session starts ======================================
platform linux -- Python 3.8.1rc1, pytest-4.6.7, py-1.8.0, pluggy-0.13.0
rootdir: /srv/projects/afu/pyhamtools/pyhamtools.git
collecting ... ^Mcollecting 46 items                                                                            ^Mcollecting 249 items                                                                           ^Mcollected 275 items                                                                            

test/test_callinfo.py EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE                                   [ 11%]
test/test_clublog.py EF.                                                                 [ 12%]
test/test_dxcluster.py ...                                                               [ 13%]
test/test_eqsl.py EF.                                                                    [ 14%]
test/test_locator_distances.py .........                                                 [ 18%]
test/test_locator_latlong_to_locator.py ....                                             [ 19%]
test/test_locator_locator_to_latlong.py ......                                           [ 21%]
test/test_locator_sunrise_sunset.py ...                                                  [ 22%]
test/test_lookuplib.py ...............                                                   [ 28%]
test/test_lookuplib_clublogapi.py FF...                                                  [ 30%]
test/test_lookuplib_clublogxml.py FF.EEEEEEEEEE                                          [ 34%]
test/test_lookuplib_countryfile.py ..EEEE                                                [ 37%]
test/test_lookuplib_gettersetter_api.py .........FFFF................................... [ 54%]
.EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE [ 86%]
EEEEEEEEEEE                                                                              [ 90%]
test/test_lookuplib_qrz.py ssssssssssssss                                                [ 95%]
test/test_lookuplib_redis.py EEE                                                         [ 96%]
test/test_lotw.py EF.E                                                                   [ 98%]
test/test_utils_freq_to_band.py .....                                                    [100%]

callsign checkup against data bases - init fails

I use the last github with the following errors
Python 3.6.1 (default, Mar 23 2017, 13:04:44) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.

from pyhamtools import LookupLib, Callinfo
my_lookuplib = LookupLib(lookuptype="clublogxml")
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python3.6/site-packages/pyhamtools/lookuplib.py", line 106, in init
self._load_clublogXML(apikey=self._apikey, cty_file=self._lib_filename)
File "/usr/lib/python3.6/site-packages/pyhamtools/lookuplib.py", line 954, in _load_clublogXML
apikey = apikey)
File "/usr/lib/python3.6/site-packages/pyhamtools/lookuplib.py", line 1025, in _download_file
if not self._check_html_response(response):
File "/usr/lib/python3.6/site-packages/pyhamtools/lookuplib.py", line 1437, in _check_html_response
raise APIKeyMissingError
pyhamtools.exceptions.APIKeyMissingError

or
Python 3.6.1 (default, Mar 23 2017, 13:04:44) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.

from pyhamtools import LookupLib, Callinfo
my_lookuplib = LookupLib(lookuptype="countryfile")
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python3.6/site-packages/pyhamtools/lookuplib.py", line 108, in init
self._load_countryfile(cty_file=self._lib_filename)
File "/usr/lib/python3.6/site-packages/pyhamtools/lookuplib.py", line 995, in _load_countryfile
cty_file = self._download_file(url=url)
File "/usr/lib/python3.6/site-packages/pyhamtools/lookuplib.py", line 1047, in _download_file
download_file.write(response.content)
TypeError: write() argument must be str, not bytes

missing class names

I used pip to get this code module, but it seems to be missing some class names.
For example: Locator, QSL, etc.
LookupLib and CallInfo are there, as well as 2 copies of a logging program

Any help would be appreciated, thanks!

Invert Longitude

The most common way to express Longitude is a positive value for east (180....0) and a negative value for west (0...-180). Currently Lookuplib returns these values inverted.

Pyhamtools should be compliant with the general understanding (as described above).

countryfile lookup fails

The countryfile lookup fails, because the country 502 "Macedonia" became "North Macedonia".
The error can be fixed by changing Macedonia to New Macedonia in the countryfilemapping.json

73, DG5YHK

Rename Swaziland into Kingdom of eSwatini

I'm not sure where the change was made (maybe in some external system that you depend on) but two country names were updated and countryfilemapping.json needs to be likewise updated to avoid KeyErrors. The required changes are:

  • "Swaziland" -> "Kingdom of eSwatini"
  • "Macedonia" -> "North Macedonia"

These are the new names of these two countries. Note that the capitalization in "Kingdom of eSwatini" is not a typo.

Deserializing json lookup data stored in redis breaks due to bad escaping

Lookup data (e.g. the clublog XML definitions) can be stored in Redis for better concurrent access amongst several applications on the server. The data is stored in the JSON format in Redis. On access, the data is retrieved and converted back from JSON into a native Python object.

This works actually well, as long as the serialized data does not contain an apostrophe (inverted comma) or a quotation mark. I found recently this problem while going through the logs of DXHeat. The country name Cote d'Ivoire (Ivery Coast) (ADIF ID 428) caused pyhamtools to through an execption whenever the corresponding country information was read from redis.

locator_to_latlong valid but incorrect results when input 8 characters

pyhamtools.locator.locator_to_latlong returns a valid but incorrect lat/long pair when called with an 8 character maidenhead [1]. Ack that doc say 4-6 character input. 8 char can be a legit (extended) maidenhead... users may overlook the doc and end up with incorrect mappings.
[1] I tested only one 8 character MH: EM69sf53. The 6 character EM69sf result is correct.

Please drop usage of "future" (and support of Python 2.7)

Hi,

Future is not compatible with Python 3.12 and will likely never be.
It's simpler to move all the project away this huge library.

Please consider remove it's usage from yor project & publish a 3.12 -compatible release.

python3-future is being removed from Debian

from future.utils

Greetings

'countryfile' lookups fail

All Callsign lookups fall - this is because in Novemember the name for DXCC entity 016 ZL9 changed from Auckland and Campbell Is. to New Zealand Subantarctic Islands. So the pyhamtools callsign dictionary builder fails. This can be fixed by adding ',"N.Z. Subantarctic Is.":16' to countryfilemapping.json

uncaught exception in Callinfo when using redis as a lookup backend

When using redis as a backend and looking up a callsign that does not exist, the following TypeError is thrown:

r = redis.Redis(host="redis", port=6379, db=0)
lib = LookupLib("redis", redis_instance=r, redis_prefix="clx")
cla = Callinfo(lib)

[....]

    spotter = cla.get_all(my_call)
  File "/usr/local/lib/python3.8/site-packages/pyhamtools/callinfo.py", line 316, in get_all
    callsign_data = self._lookup_callsign(callsign, timestamp)
  File "/usr/local/lib/python3.8/site-packages/pyhamtools/callinfo.py", line 234, in _lookup_callsign
    invalid = self._lookuplib.is_invalid_operation(callsign, timestamp)
  File "/usr/local/lib/python3.8/site-packages/pyhamtools/lookuplib.py", line 602, in is_invalid_operation
    data_dict, index = self._get_dicts_from_redis("_inv_op_", "_inv_op_index_", self._redis_prefix, callsign)
  File "/usr/local/lib/python3.8/site-packages/pyhamtools/lookuplib.py", line 422, in _get_dicts_from_redis
    raise KeyError ("No Data found in Redis for "+ item)
TypeError: can only concatenate str (not "bytes") to str

It looks like something I've missed when adding support for Python3. Should be an easy fix.

Some FT8 Call are not parsed well

Some users use some postfix to call and parser fails due that:

For example:

| TX | 2023-08-25 15:30:45 | IZ1PAI.8   | JN70xw     | -24 dB | Unknown              | 2017 Hz |  1025 km | FT8   | 20m  |
| RX | 2023-08-25 15:42:26 | RU3SN.P    | KO94wq     | -20 dB | Unknown              |  500 Hz |  1787 km | FT8   | 20m  |
| RX | 2023-08-25 15:49:26 | RU3FA.QRP  | KO84rv16   | -14 dB | Unknown              |  435 Hz |  1600 km | FT8   | 20m  |

Do not know if do some another RegEx for this (maybe if I will gather more data than just few) or just strip dot out or just try/expect it and let it as Unknown field.

Bytes need conversion to string

Need to change

download_file.write(response.content)

to

download_file.write(response.content.decode("ascii"))

in lookuplib.py (I'm running Python 3.5)

73 EA5IGC

Callsign (PJ5/OL8R) is not decoded correctly

The callsign PJ5/OL8R is decoded as "CZECH REPUBLIC" (Adif:503) instead of SABA & ST EUSTATIUS (adif: 519). There is a general problem with callsigns following the pattern xxx/yyyy (3/4characters)

KeyError: 'Kingdom of Eswatini'

Got weird error on first test of example:

Ubuntu 20.04.6 LTS
sudo apt install python3-pyhamtools

=>

Python 3.8.10 (default, May 26 2023, 14:05:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
**>>> from pyhamtools import LookupLib, Callinfo

my_lookuplib = LookupLib(lookuptype="countryfile")**
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python3/dist-packages/pyhamtools/lookuplib.py", line 111, in init
self._load_countryfile(cty_file=self._lib_filename)
File "/usr/lib/python3/dist-packages/pyhamtools/lookuplib.py", line 1027, in _load_countryfile
cty_dict = self._parse_country_file(cty_file, country_mapping_filename)
File "/usr/lib/python3/dist-packages/pyhamtools/lookuplib.py", line 1409, in _parse_country_file
entry[const.ADIF] = int(mapping[cty_list[item]["Country"]])
KeyError: 'Kingdom of Eswatini'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.