| 1 |
Metadata-Version: 2.4 |
| 2 |
Name: adif_io |
| 3 |
Version: 0.6.1 |
| 4 |
Summary: Input and output of ADIF radio amateur log files. |
| 5 |
Author-email: "Dr. Andreas Krüger, DJ3EI" <[email protected]> |
| 6 |
Project-URL: Homepage, https://gitlab.com/andreas_krueger_py/adif_io |
| 7 |
Project-URL: Repository, https://gitlab.com/andreas_krueger_py/adif_io |
| 8 |
Project-URL: Issues, https://gitlab.com/andreas_krueger_py/adif_io/-/issues |
| 9 |
Keywords: ham,amateur radio |
| 10 |
Classifier: Programming Language :: Python :: 3 |
| 11 |
Classifier: License :: OSI Approved :: Apache Software License |
| 12 |
Classifier: Operating System :: OS Independent |
| 13 |
Classifier: Development Status :: 4 - Beta |
| 14 |
Classifier: Intended Audience :: Developers |
| 15 |
Classifier: Topic :: Communications :: Ham Radio |
| 16 |
Requires-Python: >=3.10 |
| 17 |
Description-Content-Type: text/markdown |
| 18 |
License-File: LICENSE |
| 19 |
License-File: NOTICE |
| 20 |
Dynamic: license-file |
| 21 |
|
| 22 |
# This is an ADIF parser in Python. |
| 23 |
|
| 24 |
## Actual usage |
| 25 |
|
| 26 |
Main result of parsing: List of QSOs: |
| 27 |
|
| 28 |
* Each QSO is represented by a special-purpose Python mapping. |
| 29 |
* Keys in that mapping are ADIF field names in upper case, |
| 30 |
* value for a key is whatever was found in the ADIF, as a string |
| 31 |
(though some values are converted to upper case on output), |
| 32 |
* you can access individual field values via either |
| 33 |
`qso[fieldname]` or [`qso.get(fieldname)`](https://docs.python.org/3/library/stdtypes.html#dict.get) |
| 34 |
(depending on which behavior you want when your field does not exist), |
| 35 |
* and you can access all keys of that mapping via `qso.keys()`. |
| 36 |
|
| 37 |
Order of QSOs in the list is same as in ADIF file. |
| 38 |
|
| 39 |
Secondary result of parsing: The ADIF headers. |
| 40 |
This is returned as a Python mapping as well. |
| 41 |
|
| 42 |
Normally, you'd call `adif_io.read_from_file(filename)`. This reads |
| 43 |
`UTF-8`. As `UTF-8` is a proper subset of the US-ASCII presently |
| 44 |
demanded by the ADIF spec, all conforming ADI files are read. |
| 45 |
|
| 46 |
You need not know this as long as dealing with spec-conforming ADI |
| 47 |
files only, but this software expects field counts to count Unicode |
| 48 |
code points, not bytes. |
| 49 |
|
| 50 |
If you have some file that is not an ADI file, but would be an ADI |
| 51 |
file if it didn't have non-US-ASCII characters in some other encoding, |
| 52 |
you can specify that encoding (if [Python knows |
| 53 |
about](https://docs.python.org/3/library/codecs.html#standard-encodings) |
| 54 |
it). Here is an example: |
| 55 |
|
| 56 |
```python |
| 57 |
qsos, header = adif_io.read_from_file(filename, encoding="ISO-8859-15") |
| 58 |
``` |
| 59 |
|
| 60 |
Finally, you can also provide a string with an ADI-file's content, as |
| 61 |
follows: |
| 62 |
|
| 63 |
```python |
| 64 |
import adif_io |
| 65 |
|
| 66 |
qsos, header = adif_io.read_from_string( |
| 67 |
"A sample ADIF content for demonstration.\n" |
| 68 |
"<adif_ver:5>3.1.0<eoh>\n" |
| 69 |
|
| 70 |
"<QSO_DATE:8>20190714 <time_on:4>1140<CALL:5>LY0HQ" |
| 71 |
"<mode:2>CW<BAND:3>40M<RST_SENT:3>599<RST_RCVD:3>599" |
| 72 |
"<STX_STRING:2>28<SRX_STRING:4>LRMD<EOR>\n" |
| 73 |
|
| 74 |
"<QSO_DATE:8>20190714<TIME_ON:4>1130<CALL:5>SE9HQ<MODE:2>CW<FREQ:1>7" |
| 75 |
"<BAND:3>40M<RST_SENT:3>599<RST_RCVD:3>599" |
| 76 |
"<SRX_STRING:3>SSA<DXCC:3>284<EOR>") |
| 77 |
``` |
| 78 |
|
| 79 |
After this setup, `print(header)` will print out a valid ADIF file start: |
| 80 |
|
| 81 |
> <ADIF_VER:5>3.1.0 <EOH> |
| 82 |
|
| 83 |
(This starts with a blank space, as the ADIF spec demands a header must not |
| 84 |
start with the `<` character.) |
| 85 |
|
| 86 |
And |
| 87 |
|
| 88 |
```python |
| 89 |
for qso in qsos: |
| 90 |
print(qso) |
| 91 |
``` |
| 92 |
|
| 93 |
prints |
| 94 |
|
| 95 |
> <QSO_DATE:8>20190714 <TIME_ON:4>1140 <CALL:5>LY0HQ <MODE:2>CW <BAND:3>40M <RST_RCVD:3>599 <RST_SENT:3>599 <SRX_STRING:4>LRMD <STX_STRING:2>28 <EOR> |
| 96 |
> |
| 97 |
> <QSO_DATE:8>20190714 <TIME_ON:4>1130 <CALL:5>SE9HQ <FREQ:1>7 <MODE:2>CW <BAND:3>40M <DXCC:3>284 <RST_RCVD:3>599 <RST_SENT:3>599 <SRX_STRING:3>SSA <EOR> |
| 98 |
> |
| 99 |
|
| 100 |
So `str(qso)` for a single QSO generates that QSO as an ADIF string. |
| 101 |
|
| 102 |
Fine points: |
| 103 |
|
| 104 |
- The ADIF string of the headers or that of a QSO are each terminated by a `\n`. |
| 105 |
- ADIF allows lower- and upper case field names. You can feed either to this software. |
| 106 |
- Field names are consistently converted to upper case internally. |
| 107 |
- Any non-field text in the header or in a QSO or between QSOs is ignored. |
| 108 |
(This may change at some undetermined time in the future.) |
| 109 |
- Value content is always a string. |
| 110 |
- Fields with zero-length content are treated as non-existent. |
| 111 |
- The output of a single QSO has a few important fields first, |
| 112 |
then all other fields in alphabetic order. |
| 113 |
The details may change over time. |
| 114 |
- Some QSO fields, in particular `CALL` and `MODE`, are automatically converted to upper case on output. |
| 115 |
This is not done systematically (for other fields that would also benefit from this), |
| 116 |
and the details may change. |
| 117 |
|
| 118 |
## Convenience file writing |
| 119 |
|
| 120 |
You can write QSOs to a new ADI file by calling: |
| 121 |
|
| 122 |
```python |
| 123 |
adif_io.write_to_file(filename, qsos) |
| 124 |
``` |
| 125 |
|
| 126 |
If you have headers, too, do: |
| 127 |
|
| 128 |
``` |
| 129 |
adif_io.write_to_file(filename, qsos, headers) |
| 130 |
``` |
| 131 |
|
| 132 |
These two normally writes UTF-8, but that can be tweaked with an |
| 133 |
optional `encoding=` argument, similar to what `read_from_file` |
| 134 |
expects. |
| 135 |
|
| 136 |
## Time on and time off |
| 137 |
|
| 138 |
Given one `qso` dict, you can also have the QSO's start time calculated as a Python `datetime.datetime` value: |
| 139 |
|
| 140 |
adif_io.time_on(qsos[0]) |
| 141 |
|
| 142 |
If your QSO data also includes `TIME_OFF` fields (and, ideally, though |
| 143 |
not required, `QSO_DATE_OFF`), this will also work: |
| 144 |
|
| 145 |
adif_io.time_off(qsos[0]) |
| 146 |
|
| 147 |
## Geographic coordinates - to some degree |
| 148 |
|
| 149 |
ADIF uses a somewhat peculiar 11 character `XDDD MM.MMM` format to |
| 150 |
code geographic coordinates (fields `LAT` or `LON`). The more common |
| 151 |
format these days are simple floats that code degrees. You can convert |
| 152 |
from one to the other: |
| 153 |
|
| 154 |
``` |
| 155 |
adif_io.degrees_from_location("N052 26.592") # Result: 52.4432 |
| 156 |
adif_io.location_from_degrees(52.4432, True) # Result: "N052 26.592" |
| 157 |
``` |
| 158 |
|
| 159 |
The additional `bool` argument of `location_from_degrees` should be |
| 160 |
`True` for latitudes (N / S) and `False` for longitudes (E / W). |
| 161 |
|
| 162 |
## ADIF version |
| 163 |
|
| 164 |
There is little ADIF-version-specific here. (Everything should work |
| 165 |
with ADI-files of ADIF version 3.1.6, if you want to nail it.) |
| 166 |
|
| 167 |
## Output of ADIF |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
## Not supported: ADIF data types. |
| 172 |
|
| 173 |
This parser knows nothing about ADIF data types or enumerations. |
| 174 |
Everything is a string. So in that sense, this parser is fairly simple. |
| 175 |
|
| 176 |
But it does correcly handle things like: |
| 177 |
|
| 178 |
<notes:66>In this QSO, we discussed ADIF and in particular the <eor> marker. |
| 179 |
|
| 180 |
So, in that sense, this parser is _somewhat_ sophisticated. |
| 181 |
|
| 182 |
## Only ADI. |
| 183 |
|
| 184 |
This parser only handles ADI files. It knows nothing of the ADX file format. |
| 185 |
|
| 186 |
## Sample code |
| 187 |
|
| 188 |
Here is some sample code: |
| 189 |
|
| 190 |
``` |
| 191 |
import adif_io |
| 192 |
|
| 193 |
qsos_raw, adif_header = adif_io.read_from_file("log.adi") |
| 194 |
|
| 195 |
# The QSOs are probably sorted by QSO time already, but make sure: |
| 196 |
qsos_raw_sorted = sorted(qsos_raw, key = adif_io.time_on) |
| 197 |
``` |
| 198 |
|
| 199 |
Pandas / Jupyter users may want to add `import pandas as pd` |
| 200 |
up above and continue like this: |
| 201 |
|
| 202 |
``` |
| 203 |
qsos = pd.DataFrame(qsos_raw_sorted) |
| 204 |
qsos.info() |
| 205 |
``` |
| 206 |
|
| 207 |
|
| 208 |
## (Somewhat) related software |
| 209 |
|
| 210 |
I'm aware of (listing those does not neccessarily imply an endorsement): |
| 211 |
|
| 212 |
- [cabrillo](https://github.com/thxo/cabrillo) Python library |
| 213 |
- Any amateur radio QSO logging software. Open Source options include |
| 214 |
- [CQRLog](https://www.cqrlog.com/) |
| 215 |
- [not1mm](https://pypi.org/project/not1mm/) |
| 216 |
- [cloudlog]() |
| 217 |
- [wavelog](https://www.wavelog.org/) |
| 218 |
- [ADIF-Multitool](https://github.com/flwyd/adif-multitool). |