././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1769941135.0488143 adif_io-0.6.1/0000775000175000017500000000000015137624217012776 5ustar00andreasandreas././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1572099074.0 adif_io-0.6.1/LICENSE0000644000175000017500000002613613555052002013776 0ustar00andreasandreas Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769940983.0 adif_io-0.6.1/NOTICE0000644000175000017500000000024415137623767013711 0ustar00andreasandreasCopyright 2026, 2025, 2024, 2023, 2019, 2013 Andreas Krüger, DJ3EI This product includes software developed by Andreas Krüger, DJ3EI (https://dj3ei.famsik.de/). ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1769941135.0488143 adif_io-0.6.1/PKG-INFO0000644000175000017500000001603715137624217014100 0ustar00andreasandreasMetadata-Version: 2.4 Name: adif_io Version: 0.6.1 Summary: Input and output of ADIF radio amateur log files. Author-email: "Dr. Andreas Krüger, DJ3EI" Project-URL: Homepage, https://gitlab.com/andreas_krueger_py/adif_io Project-URL: Repository, https://gitlab.com/andreas_krueger_py/adif_io Project-URL: Issues, https://gitlab.com/andreas_krueger_py/adif_io/-/issues Keywords: ham,amateur radio Classifier: Programming Language :: Python :: 3 Classifier: License :: OSI Approved :: Apache Software License Classifier: Operating System :: OS Independent Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: Topic :: Communications :: Ham Radio Requires-Python: >=3.10 Description-Content-Type: text/markdown License-File: LICENSE License-File: NOTICE Dynamic: license-file # This is an ADIF parser in Python. ## Actual usage Main result of parsing: List of QSOs: * Each QSO is represented by a special-purpose Python mapping. * Keys in that mapping are ADIF field names in upper case, * value for a key is whatever was found in the ADIF, as a string (though some values are converted to upper case on output), * you can access individual field values via either `qso[fieldname]` or [`qso.get(fieldname)`](https://docs.python.org/3/library/stdtypes.html#dict.get) (depending on which behavior you want when your field does not exist), * and you can access all keys of that mapping via `qso.keys()`. Order of QSOs in the list is same as in ADIF file. Secondary result of parsing: The ADIF headers. This is returned as a Python mapping as well. Normally, you'd call `adif_io.read_from_file(filename)`. This reads `UTF-8`. As `UTF-8` is a proper subset of the US-ASCII presently demanded by the ADIF spec, all conforming ADI files are read. You need not know this as long as dealing with spec-conforming ADI files only, but this software expects field counts to count Unicode code points, not bytes. If you have some file that is not an ADI file, but would be an ADI file if it didn't have non-US-ASCII characters in some other encoding, you can specify that encoding (if [Python knows about](https://docs.python.org/3/library/codecs.html#standard-encodings) it). Here is an example: ```python qsos, header = adif_io.read_from_file(filename, encoding="ISO-8859-15") ``` Finally, you can also provide a string with an ADI-file's content, as follows: ```python import adif_io qsos, header = adif_io.read_from_string( "A sample ADIF content for demonstration.\n" "3.1.0\n" "20190714 1140LY0HQ" "CW40M599599" "28LRMD\n" "201907141130SE9HQCW7" "40M599599" "SSA284") ``` After this setup, `print(header)` will print out a valid ADIF file start: > <ADIF_VER:5>3.1.0 <EOH> (This starts with a blank space, as the ADIF spec demands a header must not start with the `<` character.) And ```python for qso in qsos: print(qso) ``` prints > <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> > > <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> > So `str(qso)` for a single QSO generates that QSO as an ADIF string. Fine points: - The ADIF string of the headers or that of a QSO are each terminated by a `\n`. - ADIF allows lower- and upper case field names. You can feed either to this software. - Field names are consistently converted to upper case internally. - Any non-field text in the header or in a QSO or between QSOs is ignored. (This may change at some undetermined time in the future.) - Value content is always a string. - Fields with zero-length content are treated as non-existent. - The output of a single QSO has a few important fields first, then all other fields in alphabetic order. The details may change over time. - Some QSO fields, in particular `CALL` and `MODE`, are automatically converted to upper case on output. This is not done systematically (for other fields that would also benefit from this), and the details may change. ## Convenience file writing You can write QSOs to a new ADI file by calling: ```python adif_io.write_to_file(filename, qsos) ``` If you have headers, too, do: ``` adif_io.write_to_file(filename, qsos, headers) ``` These two normally writes UTF-8, but that can be tweaked with an optional `encoding=` argument, similar to what `read_from_file` expects. ## Time on and time off Given one `qso` dict, you can also have the QSO's start time calculated as a Python `datetime.datetime` value: adif_io.time_on(qsos[0]) If your QSO data also includes `TIME_OFF` fields (and, ideally, though not required, `QSO_DATE_OFF`), this will also work: adif_io.time_off(qsos[0]) ## Geographic coordinates - to some degree ADIF uses a somewhat peculiar 11 character `XDDD MM.MMM` format to code geographic coordinates (fields `LAT` or `LON`). The more common format these days are simple floats that code degrees. You can convert from one to the other: ``` adif_io.degrees_from_location("N052 26.592") # Result: 52.4432 adif_io.location_from_degrees(52.4432, True) # Result: "N052 26.592" ``` The additional `bool` argument of `location_from_degrees` should be `True` for latitudes (N / S) and `False` for longitudes (E / W). ## ADIF version There is little ADIF-version-specific here. (Everything should work with ADI-files of ADIF version 3.1.6, if you want to nail it.) ## Output of ADIF ## Not supported: ADIF data types. This parser knows nothing about ADIF data types or enumerations. Everything is a string. So in that sense, this parser is fairly simple. But it does correcly handle things like: In this QSO, we discussed ADIF and in particular the marker. So, in that sense, this parser is _somewhat_ sophisticated. ## Only ADI. This parser only handles ADI files. It knows nothing of the ADX file format. ## Sample code Here is some sample code: ``` import adif_io qsos_raw, adif_header = adif_io.read_from_file("log.adi") # The QSOs are probably sorted by QSO time already, but make sure: qsos_raw_sorted = sorted(qsos_raw, key = adif_io.time_on) ``` Pandas / Jupyter users may want to add `import pandas as pd` up above and continue like this: ``` qsos = pd.DataFrame(qsos_raw_sorted) qsos.info() ``` ## (Somewhat) related software I'm aware of (listing those does not neccessarily imply an endorsement): - [cabrillo](https://github.com/thxo/cabrillo) Python library - Any amateur radio QSO logging software. Open Source options include - [CQRLog](https://www.cqrlog.com/) - [not1mm](https://pypi.org/project/not1mm/) - [cloudlog]() - [wavelog](https://www.wavelog.org/) - [ADIF-Multitool](https://github.com/flwyd/adif-multitool). ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769939965.0 adif_io-0.6.1/README.md0000644000175000017500000001433015137621775014262 0ustar00andreasandreas# This is an ADIF parser in Python. ## Actual usage Main result of parsing: List of QSOs: * Each QSO is represented by a special-purpose Python mapping. * Keys in that mapping are ADIF field names in upper case, * value for a key is whatever was found in the ADIF, as a string (though some values are converted to upper case on output), * you can access individual field values via either `qso[fieldname]` or [`qso.get(fieldname)`](https://docs.python.org/3/library/stdtypes.html#dict.get) (depending on which behavior you want when your field does not exist), * and you can access all keys of that mapping via `qso.keys()`. Order of QSOs in the list is same as in ADIF file. Secondary result of parsing: The ADIF headers. This is returned as a Python mapping as well. Normally, you'd call `adif_io.read_from_file(filename)`. This reads `UTF-8`. As `UTF-8` is a proper subset of the US-ASCII presently demanded by the ADIF spec, all conforming ADI files are read. You need not know this as long as dealing with spec-conforming ADI files only, but this software expects field counts to count Unicode code points, not bytes. If you have some file that is not an ADI file, but would be an ADI file if it didn't have non-US-ASCII characters in some other encoding, you can specify that encoding (if [Python knows about](https://docs.python.org/3/library/codecs.html#standard-encodings) it). Here is an example: ```python qsos, header = adif_io.read_from_file(filename, encoding="ISO-8859-15") ``` Finally, you can also provide a string with an ADI-file's content, as follows: ```python import adif_io qsos, header = adif_io.read_from_string( "A sample ADIF content for demonstration.\n" "3.1.0\n" "20190714 1140LY0HQ" "CW40M599599" "28LRMD\n" "201907141130SE9HQCW7" "40M599599" "SSA284") ``` After this setup, `print(header)` will print out a valid ADIF file start: > <ADIF_VER:5>3.1.0 <EOH> (This starts with a blank space, as the ADIF spec demands a header must not start with the `<` character.) And ```python for qso in qsos: print(qso) ``` prints > <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> > > <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> > So `str(qso)` for a single QSO generates that QSO as an ADIF string. Fine points: - The ADIF string of the headers or that of a QSO are each terminated by a `\n`. - ADIF allows lower- and upper case field names. You can feed either to this software. - Field names are consistently converted to upper case internally. - Any non-field text in the header or in a QSO or between QSOs is ignored. (This may change at some undetermined time in the future.) - Value content is always a string. - Fields with zero-length content are treated as non-existent. - The output of a single QSO has a few important fields first, then all other fields in alphabetic order. The details may change over time. - Some QSO fields, in particular `CALL` and `MODE`, are automatically converted to upper case on output. This is not done systematically (for other fields that would also benefit from this), and the details may change. ## Convenience file writing You can write QSOs to a new ADI file by calling: ```python adif_io.write_to_file(filename, qsos) ``` If you have headers, too, do: ``` adif_io.write_to_file(filename, qsos, headers) ``` These two normally writes UTF-8, but that can be tweaked with an optional `encoding=` argument, similar to what `read_from_file` expects. ## Time on and time off Given one `qso` dict, you can also have the QSO's start time calculated as a Python `datetime.datetime` value: adif_io.time_on(qsos[0]) If your QSO data also includes `TIME_OFF` fields (and, ideally, though not required, `QSO_DATE_OFF`), this will also work: adif_io.time_off(qsos[0]) ## Geographic coordinates - to some degree ADIF uses a somewhat peculiar 11 character `XDDD MM.MMM` format to code geographic coordinates (fields `LAT` or `LON`). The more common format these days are simple floats that code degrees. You can convert from one to the other: ``` adif_io.degrees_from_location("N052 26.592") # Result: 52.4432 adif_io.location_from_degrees(52.4432, True) # Result: "N052 26.592" ``` The additional `bool` argument of `location_from_degrees` should be `True` for latitudes (N / S) and `False` for longitudes (E / W). ## ADIF version There is little ADIF-version-specific here. (Everything should work with ADI-files of ADIF version 3.1.6, if you want to nail it.) ## Output of ADIF ## Not supported: ADIF data types. This parser knows nothing about ADIF data types or enumerations. Everything is a string. So in that sense, this parser is fairly simple. But it does correcly handle things like: In this QSO, we discussed ADIF and in particular the marker. So, in that sense, this parser is _somewhat_ sophisticated. ## Only ADI. This parser only handles ADI files. It knows nothing of the ADX file format. ## Sample code Here is some sample code: ``` import adif_io qsos_raw, adif_header = adif_io.read_from_file("log.adi") # The QSOs are probably sorted by QSO time already, but make sure: qsos_raw_sorted = sorted(qsos_raw, key = adif_io.time_on) ``` Pandas / Jupyter users may want to add `import pandas as pd` up above and continue like this: ``` qsos = pd.DataFrame(qsos_raw_sorted) qsos.info() ``` ## (Somewhat) related software I'm aware of (listing those does not neccessarily imply an endorsement): - [cabrillo](https://github.com/thxo/cabrillo) Python library - Any amateur radio QSO logging software. Open Source options include - [CQRLog](https://www.cqrlog.com/) - [not1mm](https://pypi.org/project/not1mm/) - [cloudlog]() - [wavelog](https://www.wavelog.org/) - [ADIF-Multitool](https://github.com/flwyd/adif-multitool). ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769940517.0 adif_io-0.6.1/pyproject.toml0000644000175000017500000000213015137623045015702 0ustar00andreasandreas# I find this documentation helpful when editing this file: # https://packaging.python.org/en/latest/guides/writing-pyproject-toml/ # https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html [build-system] requires = ["setuptools"] build-backend = "setuptools.build_meta" [project] authors = [ {name = "Dr. Andreas Krüger, DJ3EI", email = "dj3ei@famsik.de"}, ] name = "adif_io" description = "Input and output of ADIF radio amateur log files." readme = "README.md" requires-python = ">=3.10" keywords = ["ham", "amateur radio"] # https://pypi.org/classifiers/ classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Topic :: Communications :: Ham Radio" ] version = "0.6.1" [project.urls] Homepage = "https://gitlab.com/andreas_krueger_py/adif_io" Repository = "https://gitlab.com/andreas_krueger_py/adif_io" Issues = "https://gitlab.com/andreas_krueger_py/adif_io/-/issues" [tool.isort] profile = "black" ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1769941135.0488143 adif_io-0.6.1/setup.cfg0000664000175000017500000000004615137624217014617 0ustar00andreasandreas[egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1769941135.0168138 adif_io-0.6.1/src/0000775000175000017500000000000015137624217013565 5ustar00andreasandreas././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1769941135.0488143 adif_io-0.6.1/src/adif_io/0000775000175000017500000000000015137624217015157 5ustar00andreasandreas././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769940968.0 adif_io-0.6.1/src/adif_io/__init__.py0000644000175000017500000002551015137623750017272 0ustar00andreasandreas# Copyright 2019, 2023, 2025, 2026 Andreas Krüger, DJ3EI # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # This is an ADIF parser in Python. # It knows nothing about ADIF data types or enumerations, # everything is a string, so it is fairly simple. # But it does correcly handle things like: # In this QSO, we discussed ADIF and in particular the marker. # So, in that sense, this parser is somewhat sophisticated. # Main result of parsing: List of QSOs. # Each QSO is one Python dict. # Keys in that dict are ADIF field names in upper case, # value for a key is whatever was found in the ADIF, as a string. # Order of QSOs in the list is same as in ADIF file. import math import re from collections.abc import MutableMapping from datetime import datetime, timedelta, timezone from typing import Iterator, Optional PROGRAMM_VERSION = "0.6.1" class AdifError(Exception): """Base error.""" pass class AdifHeaderWithoutEOHError(AdifError): """Error for header found, but not terminated with """ pass class AdifDuplicateFieldError(AdifError): """Error for duplicate fileds in one QSO record or in the header.""" pass class _SaneStringMapping(MutableMapping[str, str]): def __init__(self, raw: dict[str, str]): self._d: dict[str, str] = {} for key in raw.keys(): value = raw[key] if value is None or len(value) == 0: pass else: self._d[key.upper()] = str(value) def __getitem__(self, key: str) -> str: return self._d[key.upper()] def __setitem__(self, key: str, value: str) -> None: if value is None or value == "": ku = key.upper() if ku in self._d: del self._d[ku] else: self._d[key.upper()] = str(value) def __delitem__(self, key: str) -> None: del self._d[key.upper()] def __iter__(self) -> Iterator[str]: return iter(self._d) def __len__(self) -> int: return len(self._d) class QSO(_SaneStringMapping): def __str__(self) -> str: return qso_to_adif(self) # Some type definition; however, it may change. class Headers(_SaneStringMapping): def __str__(self) -> str: return headers_to_adif(self) def qso_from_dict(d: dict[str, str]) -> QSO: """Official API to convert a Python dict to a QSO. Intended to be stable long-term. """ return QSO(d) def headers_from_dict(d: dict[str, str]) -> Headers: """Official API to convert a Python dict to ADIF file headers. Has a slim chance to remain stable long-term. """ return Headers(d) def read_from_string(adif_string: str) -> tuple[list[QSO], Headers]: """Read an ADIF string. Return QSO list and any headers found.""" # The ADIF file header keys and values, if any. adif_headers: dict[str, str] = {} header_field_re = re.compile(r"<((eoh)|(\w+)\:(\d+)(\:[^>]+)?)>", re.IGNORECASE) field_re = re.compile(r"<((eor)|(\w+)\:(\d+)(\:[^>]+)?)>", re.IGNORECASE) qsos: list[QSO] = [] cursor = 0 if adif_string[0] != "<": # Input has ADIF header. Read all header fields. eoh_found = False while not eoh_found: header_field_mo = header_field_re.search(adif_string, cursor) if header_field_mo: if header_field_mo.group(2): eoh_found = True cursor = header_field_mo.end(0) else: field = header_field_mo.group(3).upper() value_start = header_field_mo.end(0) value_end = value_start + int(header_field_mo.group(4)) value = adif_string[value_start:value_end] if field in adif_headers: raise AdifDuplicateFieldError( f'Duplication in ADI header, {field} previously "{adif_headers[field]}", now "{value}".' ) adif_headers[field] = value cursor = value_end else: raise AdifHeaderWithoutEOHError( " marker missing after ADIF header." ) one_qso: dict[str, str] = {} field_mo = field_re.search(adif_string, cursor) while field_mo: if field_mo.group(2): # found: qsos.append(qso_from_dict(one_qso)) one_qso = {} cursor = field_mo.end(0) else: # Field found: field = field_mo.group(3).upper() value_start = field_mo.end(0) value_end = value_start + int(field_mo.group(4)) value = adif_string[value_start:value_end] if field in one_qso: raise AdifDuplicateFieldError( f'Duplication in qso {one_qso}, {field} previously "{one_qso[field]}", now "{value}".' ) one_qso[field] = value cursor = value_end field_mo = field_re.search(adif_string, cursor) return (qsos, headers_from_dict(adif_headers)) def read_from_file(filename: str, encoding: str = "UTF-8") -> tuple[list[QSO], Headers]: """Read ADIF from a file.""" with open(filename, encoding=encoding) as adif_file: adif_string = adif_file.read() return read_from_string(adif_string) _ONE_DAY = timedelta(days=1) def time_on(one_qso: QSO) -> datetime: """Convert the on-time of a QSO to Python datetime.""" date = one_qso["QSO_DATE"] y = int(date[0:4]) mo = int(date[4:6]) d = int(date[6:8]) time = one_qso["TIME_ON"] h = int(time[0:2]) mi = int(time[2:4]) s = int(time[4:6]) if len(time) == 6 else 0 return datetime(y, mo, d, h, mi, s, tzinfo=timezone.utc) def time_off(one_qso: QSO) -> datetime: """Convert the off-time of a QSO to Python datetime.""" if "QSO_DATE_OFF" in one_qso: date = one_qso["QSO_DATE_OFF"] y = int(date[0:4]) mo = int(date[4:6]) d = int(date[6:8]) time = one_qso["TIME_OFF"] h = int(time[0:2]) mi = int(time[2:4]) s = int(time[4:6]) if len(time) == 6 else 0 return datetime(y, mo, d, h, mi, s, tzinfo=timezone.utc) else: date = one_qso["QSO_DATE"] y = int(date[0:4]) mo = int(date[4:6]) d = int(date[6:8]) time = one_qso["TIME_OFF"] h = int(time[0:2]) mi = int(time[2:4]) s = int(time[4:6]) if len(time) == 6 else 0 time_off_maybe = datetime(y, mo, d, h, mi, s, tzinfo=timezone.utc) if time_on(one_qso) < time_off_maybe: return time_off_maybe else: return time_off_maybe + _ONE_DAY def degrees_from_location(adif: str) -> float: """Convert an ADIF location string to degrees.""" x = adif[0] deg_i = int(adif[1:4]) min = float(adif[5:]) deg = deg_i + min / 60 return deg if x in ["N", "E", "n", "e"] else -deg def location_from_degrees(degrees: float, lat: bool) -> str: """Convert degrees to an ADIF location string, either latitude or longitude. If the `lat` parameter is true, N / S are used, if false, E / W. """ if lat: if degrees < 0.0: x = "S" else: x = "N" else: if degrees < 0.0: x = "W" else: x = "E" degrees_abs = abs(degrees) deg_num = int(math.floor(degrees_abs)) min_num = (degrees_abs - deg_num) * 60 return f"{x}{deg_num:03d} {min_num:06.3f}" def headers_to_adif(headers: Headers) -> str: """Transform some headers to an ADIF string.""" result = "" for key in sorted(headers.keys()): value = headers[key] if value is None: pass # Can't really happen. else: value_s = str(value) if 0 == len(value_s) or key is None or 0 == len(key): pass # Can't really happen. else: if 0 == len(result): result = f" <{key}:{len(value_s)}>{value_s}" else: result += f" <{key}:{len(value_s)}>{value_s}" result += " \n" return result _ESSENTIAL_KEYS = [ "QSO_DATE", "TIME_ON", "CALL", "FREQ", "MODE", ] def qso_to_adif(qso: QSO) -> str: """Transform a qso to an ADIF string.""" result = "" for key in _ESSENTIAL_KEYS: if key in qso: value = qso[key] if value is None: pass # Can't really happen. else: value_s = str(value) if 0 == len(value_s) or key is None or 0 == len(key): pass # Can't really happen. else: if 0 == len(result): result = f"<{key}:{len(value_s)}>{value_s.upper()}" else: result += f" <{key}:{len(value_s)}>{value_s.upper()}" for key in sorted(k for k in qso.keys() if k not in _ESSENTIAL_KEYS): value = qso[key] if value is None: pass # Can't really happen. else: value_s = str(value) if 0 == len(value_s) or key is None or 0 == len(key): pass # Can't really happen. else: if 0 == len(result): result = f"<{key}:{len(value_s)}>{value_s}" else: result += f" <{key}:{len(value_s)}>{value_s}" result += " \n" return result def write_to_file( filename: str, qsos: list[QSO], headers: Optional[Headers] = None, encoding: str = "UTF-8", ) -> None: with open(filename, encoding=encoding) as adif_file: adif_file.write("ADI file written by Python's adif_io\n") if headers is None: headers = Headers({}) if "ADIF_VER" not in headers: adif_file.write(" 3.1.6") if "CREATED_TIMESTAMP" not in headers: dt = datetime.utcnow().strftime("%Y%m%d %H%M%S") adif_file.write(f" {dt}") if "PROGRAMID" not in headers: adif_file.write(" Python adif_io") if "PROGRAMMVERSION" not in headers: adif_file.write( f" {PROGRAMM_VERSION}" ) adif_file.write(headers_to_adif(headers)) for qso in qsos: adif_file.write(qso_to_adif(qso)) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1769941135.0488143 adif_io-0.6.1/src/adif_io.egg-info/0000775000175000017500000000000015137624217016651 5ustar00andreasandreas././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769941135.0 adif_io-0.6.1/src/adif_io.egg-info/PKG-INFO0000644000175000017500000001603715137624217017753 0ustar00andreasandreasMetadata-Version: 2.4 Name: adif_io Version: 0.6.1 Summary: Input and output of ADIF radio amateur log files. Author-email: "Dr. Andreas Krüger, DJ3EI" Project-URL: Homepage, https://gitlab.com/andreas_krueger_py/adif_io Project-URL: Repository, https://gitlab.com/andreas_krueger_py/adif_io Project-URL: Issues, https://gitlab.com/andreas_krueger_py/adif_io/-/issues Keywords: ham,amateur radio Classifier: Programming Language :: Python :: 3 Classifier: License :: OSI Approved :: Apache Software License Classifier: Operating System :: OS Independent Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: Topic :: Communications :: Ham Radio Requires-Python: >=3.10 Description-Content-Type: text/markdown License-File: LICENSE License-File: NOTICE Dynamic: license-file # This is an ADIF parser in Python. ## Actual usage Main result of parsing: List of QSOs: * Each QSO is represented by a special-purpose Python mapping. * Keys in that mapping are ADIF field names in upper case, * value for a key is whatever was found in the ADIF, as a string (though some values are converted to upper case on output), * you can access individual field values via either `qso[fieldname]` or [`qso.get(fieldname)`](https://docs.python.org/3/library/stdtypes.html#dict.get) (depending on which behavior you want when your field does not exist), * and you can access all keys of that mapping via `qso.keys()`. Order of QSOs in the list is same as in ADIF file. Secondary result of parsing: The ADIF headers. This is returned as a Python mapping as well. Normally, you'd call `adif_io.read_from_file(filename)`. This reads `UTF-8`. As `UTF-8` is a proper subset of the US-ASCII presently demanded by the ADIF spec, all conforming ADI files are read. You need not know this as long as dealing with spec-conforming ADI files only, but this software expects field counts to count Unicode code points, not bytes. If you have some file that is not an ADI file, but would be an ADI file if it didn't have non-US-ASCII characters in some other encoding, you can specify that encoding (if [Python knows about](https://docs.python.org/3/library/codecs.html#standard-encodings) it). Here is an example: ```python qsos, header = adif_io.read_from_file(filename, encoding="ISO-8859-15") ``` Finally, you can also provide a string with an ADI-file's content, as follows: ```python import adif_io qsos, header = adif_io.read_from_string( "A sample ADIF content for demonstration.\n" "3.1.0\n" "20190714 1140LY0HQ" "CW40M599599" "28LRMD\n" "201907141130SE9HQCW7" "40M599599" "SSA284") ``` After this setup, `print(header)` will print out a valid ADIF file start: > <ADIF_VER:5>3.1.0 <EOH> (This starts with a blank space, as the ADIF spec demands a header must not start with the `<` character.) And ```python for qso in qsos: print(qso) ``` prints > <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> > > <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> > So `str(qso)` for a single QSO generates that QSO as an ADIF string. Fine points: - The ADIF string of the headers or that of a QSO are each terminated by a `\n`. - ADIF allows lower- and upper case field names. You can feed either to this software. - Field names are consistently converted to upper case internally. - Any non-field text in the header or in a QSO or between QSOs is ignored. (This may change at some undetermined time in the future.) - Value content is always a string. - Fields with zero-length content are treated as non-existent. - The output of a single QSO has a few important fields first, then all other fields in alphabetic order. The details may change over time. - Some QSO fields, in particular `CALL` and `MODE`, are automatically converted to upper case on output. This is not done systematically (for other fields that would also benefit from this), and the details may change. ## Convenience file writing You can write QSOs to a new ADI file by calling: ```python adif_io.write_to_file(filename, qsos) ``` If you have headers, too, do: ``` adif_io.write_to_file(filename, qsos, headers) ``` These two normally writes UTF-8, but that can be tweaked with an optional `encoding=` argument, similar to what `read_from_file` expects. ## Time on and time off Given one `qso` dict, you can also have the QSO's start time calculated as a Python `datetime.datetime` value: adif_io.time_on(qsos[0]) If your QSO data also includes `TIME_OFF` fields (and, ideally, though not required, `QSO_DATE_OFF`), this will also work: adif_io.time_off(qsos[0]) ## Geographic coordinates - to some degree ADIF uses a somewhat peculiar 11 character `XDDD MM.MMM` format to code geographic coordinates (fields `LAT` or `LON`). The more common format these days are simple floats that code degrees. You can convert from one to the other: ``` adif_io.degrees_from_location("N052 26.592") # Result: 52.4432 adif_io.location_from_degrees(52.4432, True) # Result: "N052 26.592" ``` The additional `bool` argument of `location_from_degrees` should be `True` for latitudes (N / S) and `False` for longitudes (E / W). ## ADIF version There is little ADIF-version-specific here. (Everything should work with ADI-files of ADIF version 3.1.6, if you want to nail it.) ## Output of ADIF ## Not supported: ADIF data types. This parser knows nothing about ADIF data types or enumerations. Everything is a string. So in that sense, this parser is fairly simple. But it does correcly handle things like: In this QSO, we discussed ADIF and in particular the marker. So, in that sense, this parser is _somewhat_ sophisticated. ## Only ADI. This parser only handles ADI files. It knows nothing of the ADX file format. ## Sample code Here is some sample code: ``` import adif_io qsos_raw, adif_header = adif_io.read_from_file("log.adi") # The QSOs are probably sorted by QSO time already, but make sure: qsos_raw_sorted = sorted(qsos_raw, key = adif_io.time_on) ``` Pandas / Jupyter users may want to add `import pandas as pd` up above and continue like this: ``` qsos = pd.DataFrame(qsos_raw_sorted) qsos.info() ``` ## (Somewhat) related software I'm aware of (listing those does not neccessarily imply an endorsement): - [cabrillo](https://github.com/thxo/cabrillo) Python library - Any amateur radio QSO logging software. Open Source options include - [CQRLog](https://www.cqrlog.com/) - [not1mm](https://pypi.org/project/not1mm/) - [cloudlog]() - [wavelog](https://www.wavelog.org/) - [ADIF-Multitool](https://github.com/flwyd/adif-multitool). ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769941135.0 adif_io-0.6.1/src/adif_io.egg-info/SOURCES.txt0000664000175000017500000000051315137624217020534 0ustar00andreasandreasLICENSE NOTICE README.md pyproject.toml src/adif_io/__init__.py src/adif_io.egg-info/PKG-INFO src/adif_io.egg-info/SOURCES.txt src/adif_io.egg-info/dependency_links.txt src/adif_io.egg-info/top_level.txt tests/test_adif_import.py tests/test_adif_string_generation.py tests/test_degree_translation.py tests/test_header_generation.py././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769941135.0 adif_io-0.6.1/src/adif_io.egg-info/dependency_links.txt0000664000175000017500000000000115137624217022717 0ustar00andreasandreas ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1769941135.0 adif_io-0.6.1/src/adif_io.egg-info/top_level.txt0000664000175000017500000000001015137624217021372 0ustar00andreasandreasadif_io ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1769941135.0488143 adif_io-0.6.1/tests/0000775000175000017500000000000015137624217014140 5ustar00andreasandreas././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1732791387.0 adif_io-0.6.1/tests/test_adif_import.py0000644000175000017500000001667314722046133020053 0ustar00andreasandreasfrom datetime import datetime, timezone import pytest import adif_io def test_adif_str_import() -> None: """Plain vanilla import test.""" qsos, header = adif_io.read_from_string( "A sample ADIF content for demonstration.\n" "3.1.3\n" "20190714 1140LY0HQ" "CW40M599599" "28LRMD\n" "201907141130SE9HQCW7" "40M599599" "SSA284" ) assert [ { "QSO_DATE": "20190714", "TIME_ON": "1140", "CALL": "LY0HQ", "MODE": "CW", "BAND": "40M", "RST_SENT": "599", "RST_RCVD": "599", "STX_STRING": "28", "SRX_STRING": "LRMD", }, { "QSO_DATE": "20190714", "TIME_ON": "1130", "CALL": "SE9HQ", "MODE": "CW", "FREQ": "7", "BAND": "40M", "RST_SENT": "599", "RST_RCVD": "599", "SRX_STRING": "SSA", "DXCC": "284", }, ] == qsos assert {"ADIF_VER": "3.1.3"} == header assert datetime( year=2019, month=7, day=14, hour=11, minute=40, second=0, tzinfo=timezone.utc ) == adif_io.time_on(qsos[0]) assert datetime( year=2019, month=7, day=14, hour=11, minute=30, second=0, tzinfo=timezone.utc ) == adif_io.time_on(qsos[1]) with pytest.raises(KeyError) as exinfo: adif_io.time_off(qsos[0]) exinfo.match("TIME_OFF") def test_adif_file_import() -> None: """Plain vanilla import test.""" qsos, header = adif_io.read_from_file("tests/vanilla.adi") assert [ { "QSO_DATE": "20190714", "TIME_ON": "1140", "CALL": "LY0HQ", "MODE": "CW", "BAND": "40M", "RST_SENT": "599", "RST_RCVD": "599", "STX_STRING": "28", "SRX_STRING": "LRMD", }, { "QSO_DATE": "20190714", "TIME_ON": "113027", "CALL": "SE9HQ", "MODE": "CW", "FREQ": "7", "BAND": "40M", "RST_SENT": "599", "RST_RCVD": "599", "SRX_STRING": "SSA", "DXCC": "284", }, ] == qsos assert {"ADIF_VER": "3.1.3"} == header def test_convert_field_names_to_upper_case() -> None: qsos, header = adif_io.read_from_string( "20190714 1140LY0HQ" "CW40M599599" "28LRMD\n" "201907141130SE9HQCW7" "40M599599" "Let us see that the example from the README also works:" "In this QSO, we discussed ADIF and in particular the marker." "SSA284" ) assert [ { "QSO_DATE": "20190714", "TIME_ON": "1140", "CALL": "LY0HQ", "MODE": "CW", "BAND": "40M", "RST_SENT": "599", "RST_RCVD": "599", "STX_STRING": "28", "SRX_STRING": "LRMD", }, { "QSO_DATE": "20190714", "TIME_ON": "1130", "CALL": "SE9HQ", "MODE": "CW", "FREQ": "7", "BAND": "40M", "RST_SENT": "599", "RST_RCVD": "599", "SRX_STRING": "SSA", "DXCC": "284", "NOTES": "In this QSO, we discussed ADIF and in particular the marker.", }, ] == qsos assert {} == header def test_nonexisting_fields_are_handled_the_python_way() -> None: qsos, header = adif_io.read_from_string( "201907141130SE9HQCW7" "40M599599" "Let us see that the example from the README also works:" "In this QSO, we discussed ADIF and in particular the marker." "SSA284" ) assert qsos[0]["TIME_ON"] == "1130" with pytest.raises(KeyError) as ex: qsos[0]["TIME_OFF"] assert ex.match("TIME_OFF") assert qsos[0].get("TIME_OFF") is None assert "not too much later" == qsos[0].get("TIME_OFF", "not too much later") def test_need_eoh_after_header() -> None: with pytest.raises(adif_io.AdifHeaderWithoutEOHError): qsos, header = adif_io.read_from_string("Some header 20230606") def test_double_header_field_rejected() -> None: with pytest.raises(adif_io.AdifDuplicateFieldError) as exinfo: qsos, header = adif_io.read_from_string( "A sample ADIF content for demonstration.\n" "3.1.33.0.2\n" "20190714 1140LY0HQ" "CW40M599599" "28LRMD\n" "201907141130SE9HQCW7" "40M599599" "SSA284" "20230606" ) exinfo.match(r"3\.1\.3") exinfo.match(r"3\.0\.2") exinfo.match("ADIF_VER") def test_double_qso_field_rejected() -> None: with pytest.raises(adif_io.AdifDuplicateFieldError) as exinfo: adif_io.read_from_string( "A sample ADIF content for demonstration.\n" "3.1.3\n" "20190714 1140LY0HQ" "CW40M599599" "28LRMD\n" "201907141130SE9HQCW7" "40M599599" "SSA284" "20230606" ) exinfo.match("20190714") exinfo.match("20230606") exinfo.match("QSO_DATE") def test_time_off_date_heuristic() -> None: qsos, header = adif_io.read_from_string( "A sample ADIF content for demonstration.\n" "3.1.3\n" "20190714 114018 2358 \n" "20190714 115019 1023 \n" "20190714 115020 20190720 115152 \n" ) assert datetime( year=2019, month=7, day=14, hour=11, minute=40, second=18, tzinfo=timezone.utc ) == adif_io.time_on(qsos[0]) assert datetime( year=2019, month=7, day=14, hour=23, minute=58, tzinfo=timezone.utc ) == adif_io.time_off(qsos[0]) assert datetime( year=2019, month=7, day=14, hour=11, minute=50, second=19, tzinfo=timezone.utc ) == adif_io.time_on(qsos[1]) assert datetime( year=2019, month=7, day=15, hour=10, minute=23, tzinfo=timezone.utc ) == adif_io.time_off(qsos[1]) assert datetime( year=2019, month=7, day=14, hour=11, minute=50, second=20, tzinfo=timezone.utc ) == adif_io.time_on(qsos[2]) assert datetime( year=2019, month=7, day=20, hour=11, minute=51, second=52, tzinfo=timezone.utc ) == adif_io.time_off(qsos[2]) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1724664246.0 adif_io-0.6.1/tests/test_adif_string_generation.py0000644000175000017500000000376114663044666022271 0ustar00andreasandreasfrom typing import cast import adif_io def test_vanilla_adif_string_generation() -> None: """Plain vanilla test of generating an ADIF string.""" wanted_string = ( " 3.1.0 Lorem \n" "DJ3EI Unicode is here to stay!🤗 579 \n" ) qsos, headers = adif_io.read_from_string(wanted_string) assert 2 == len(headers) assert 1 == len(qsos) assert wanted_string == f"{str(headers)}{str(qsos[0])}" def test_no_empty_adif_header_fields() -> None: headers = adif_io.headers_from_dict( cast( dict[str, str], {"ADIF_VER": "", "PROGRAMMID": "Cool Programm", "PROGRAMMVERSION": None}, ) ) headers["ADIF_VER"] = "" headers["PROGRAMMVERSION"] = cast(str, None) assert " Cool Programm \n" == str(headers) def test_no_empty_adif_qso_fields() -> None: qso = adif_io.qso_from_dict( cast( dict[str, str], { "CALL": "dj3ei", "FREQ": "", "QSO_DATE": None, "NOTE": None, "RST_SEND": "", "RST_RCVD": "599", "TIME_ON": "0116", }, ) ) assert "0116 DJ3EI 599 \n" == str(qso) qso["TIME_ON"] = cast(str, None) qso["MODE"] = "" qso["MY_CALL"] = "" assert "DJ3EI 599 \n" == str(qso) qso["MODE"] = "ssb" assert "DJ3EI SSB 599 \n" == str(qso) qso["MY_CALL"] = cast(str, None) qso["TIME_ON"] = "0143" assert "0143 DJ3EI SSB 599 \n" == str( qso ) del qso["TIME_ON"] assert "DJ3EI SSB 599 \n" == str(qso) assert 3 == len(qso) qso2 = adif_io.qso_from_dict({"NOTE": "not much as far as QSOs go."}) assert "not much as far as QSOs go. \n" == str(qso2) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1686060806.0 adif_io-0.6.1/tests/test_degree_translation.py0000644000175000017500000000153314437637406021430 0ustar00andreasandreasfrom pytest import approx import adif_io def test_plain_vanilla() -> None: assert approx(52 + 26.592 / 60) == adif_io.degrees_from_location("N052 26.592") assert "N052 26.592" == adif_io.location_from_degrees(52 + 26.592 / 60, True) assert approx(-(17 + 3.123 / 60)) == adif_io.degrees_from_location("S017 03.123") assert "S017 03.123" == adif_io.location_from_degrees(-(17 + 3.123 / 60), True) assert approx(0.001 / 60) == adif_io.degrees_from_location("E000 00.001") assert "E000 00.001" == adif_io.location_from_degrees(0.001 / 60, False) assert approx(-90) == adif_io.degrees_from_location("W090 00.000") assert "W090 00.000" == adif_io.location_from_degrees(-90, False) assert approx(179.5) == adif_io.degrees_from_location("E179 30.000") assert "E179 30.000" == adif_io.location_from_degrees(179.5, False) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1724664246.0 adif_io-0.6.1/tests/test_header_generation.py0000644000175000017500000000074614663044666021230 0ustar00andreasandreasimport adif_io def test_vanilla_header_generation() -> None: """Test a plain vanilla case of header generation.""" RAW_HEADER = { "adif_ver": "3.1.3", "CREATED_TIMESTAMP": "20240825 221514", "PROGRAMID": "PyCharme Community Edition", "PROGRAMMVERSION": "2024.1.3", } header = adif_io.headers_from_dict(RAW_HEADER) assert len(RAW_HEADER) == len(header) for key in RAW_HEADER.keys(): assert RAW_HEADER[key] == header[key]