qspylib 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
1
+ # This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3
+
4
+ name: Python package
5
+
6
+ on:
7
+ push:
8
+ branches: [ "main" ]
9
+ pull_request:
10
+ branches: [ "main" ]
11
+
12
+ jobs:
13
+ build:
14
+
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ python-version: ["3.9", "3.10", "3.11"]
20
+
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+ - name: Set up Python ${{ matrix.python-version }}
24
+ uses: actions/setup-python@v3
25
+ with:
26
+ python-version: ${{ matrix.python-version }}
27
+ - name: Install dependencies
28
+ run: |
29
+ python -m pip install --upgrade pip
30
+ python -m pip install flake8 pytest
31
+ if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
32
+ - name: Lint with flake8
33
+ run: |
34
+ # stop the build if there are Python syntax errors or undefined names
35
+ flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
36
+ # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
37
+ flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
38
+ - name: Test with pytest
39
+ run: |
40
+ pytest
@@ -0,0 +1,3 @@
1
+ /.pytest_cache
2
+ /.vscode
3
+ /src/qspylib/__pycache__
qspylib-0.0.1/LICENSE ADDED
@@ -0,0 +1,373 @@
1
+ Mozilla Public License Version 2.0
2
+ ==================================
3
+
4
+ 1. Definitions
5
+ --------------
6
+
7
+ 1.1. "Contributor"
8
+ means each individual or legal entity that creates, contributes to
9
+ the creation of, or owns Covered Software.
10
+
11
+ 1.2. "Contributor Version"
12
+ means the combination of the Contributions of others (if any) used
13
+ by a Contributor and that particular Contributor's Contribution.
14
+
15
+ 1.3. "Contribution"
16
+ means Covered Software of a particular Contributor.
17
+
18
+ 1.4. "Covered Software"
19
+ means Source Code Form to which the initial Contributor has attached
20
+ the notice in Exhibit A, the Executable Form of such Source Code
21
+ Form, and Modifications of such Source Code Form, in each case
22
+ including portions thereof.
23
+
24
+ 1.5. "Incompatible With Secondary Licenses"
25
+ means
26
+
27
+ (a) that the initial Contributor has attached the notice described
28
+ in Exhibit B to the Covered Software; or
29
+
30
+ (b) that the Covered Software was made available under the terms of
31
+ version 1.1 or earlier of the License, but not also under the
32
+ terms of a Secondary License.
33
+
34
+ 1.6. "Executable Form"
35
+ means any form of the work other than Source Code Form.
36
+
37
+ 1.7. "Larger Work"
38
+ means a work that combines Covered Software with other material, in
39
+ a separate file or files, that is not Covered Software.
40
+
41
+ 1.8. "License"
42
+ means this document.
43
+
44
+ 1.9. "Licensable"
45
+ means having the right to grant, to the maximum extent possible,
46
+ whether at the time of the initial grant or subsequently, any and
47
+ all of the rights conveyed by this License.
48
+
49
+ 1.10. "Modifications"
50
+ means any of the following:
51
+
52
+ (a) any file in Source Code Form that results from an addition to,
53
+ deletion from, or modification of the contents of Covered
54
+ Software; or
55
+
56
+ (b) any new file in Source Code Form that contains any Covered
57
+ Software.
58
+
59
+ 1.11. "Patent Claims" of a Contributor
60
+ means any patent claim(s), including without limitation, method,
61
+ process, and apparatus claims, in any patent Licensable by such
62
+ Contributor that would be infringed, but for the grant of the
63
+ License, by the making, using, selling, offering for sale, having
64
+ made, import, or transfer of either its Contributions or its
65
+ Contributor Version.
66
+
67
+ 1.12. "Secondary License"
68
+ means either the GNU General Public License, Version 2.0, the GNU
69
+ Lesser General Public License, Version 2.1, the GNU Affero General
70
+ Public License, Version 3.0, or any later versions of those
71
+ licenses.
72
+
73
+ 1.13. "Source Code Form"
74
+ means the form of the work preferred for making modifications.
75
+
76
+ 1.14. "You" (or "Your")
77
+ means an individual or a legal entity exercising rights under this
78
+ License. For legal entities, "You" includes any entity that
79
+ controls, is controlled by, or is under common control with You. For
80
+ purposes of this definition, "control" means (a) the power, direct
81
+ or indirect, to cause the direction or management of such entity,
82
+ whether by contract or otherwise, or (b) ownership of more than
83
+ fifty percent (50%) of the outstanding shares or beneficial
84
+ ownership of such entity.
85
+
86
+ 2. License Grants and Conditions
87
+ --------------------------------
88
+
89
+ 2.1. Grants
90
+
91
+ Each Contributor hereby grants You a world-wide, royalty-free,
92
+ non-exclusive license:
93
+
94
+ (a) under intellectual property rights (other than patent or trademark)
95
+ Licensable by such Contributor to use, reproduce, make available,
96
+ modify, display, perform, distribute, and otherwise exploit its
97
+ Contributions, either on an unmodified basis, with Modifications, or
98
+ as part of a Larger Work; and
99
+
100
+ (b) under Patent Claims of such Contributor to make, use, sell, offer
101
+ for sale, have made, import, and otherwise transfer either its
102
+ Contributions or its Contributor Version.
103
+
104
+ 2.2. Effective Date
105
+
106
+ The licenses granted in Section 2.1 with respect to any Contribution
107
+ become effective for each Contribution on the date the Contributor first
108
+ distributes such Contribution.
109
+
110
+ 2.3. Limitations on Grant Scope
111
+
112
+ The licenses granted in this Section 2 are the only rights granted under
113
+ this License. No additional rights or licenses will be implied from the
114
+ distribution or licensing of Covered Software under this License.
115
+ Notwithstanding Section 2.1(b) above, no patent license is granted by a
116
+ Contributor:
117
+
118
+ (a) for any code that a Contributor has removed from Covered Software;
119
+ or
120
+
121
+ (b) for infringements caused by: (i) Your and any other third party's
122
+ modifications of Covered Software, or (ii) the combination of its
123
+ Contributions with other software (except as part of its Contributor
124
+ Version); or
125
+
126
+ (c) under Patent Claims infringed by Covered Software in the absence of
127
+ its Contributions.
128
+
129
+ This License does not grant any rights in the trademarks, service marks,
130
+ or logos of any Contributor (except as may be necessary to comply with
131
+ the notice requirements in Section 3.4).
132
+
133
+ 2.4. Subsequent Licenses
134
+
135
+ No Contributor makes additional grants as a result of Your choice to
136
+ distribute the Covered Software under a subsequent version of this
137
+ License (see Section 10.2) or under the terms of a Secondary License (if
138
+ permitted under the terms of Section 3.3).
139
+
140
+ 2.5. Representation
141
+
142
+ Each Contributor represents that the Contributor believes its
143
+ Contributions are its original creation(s) or it has sufficient rights
144
+ to grant the rights to its Contributions conveyed by this License.
145
+
146
+ 2.6. Fair Use
147
+
148
+ This License is not intended to limit any rights You have under
149
+ applicable copyright doctrines of fair use, fair dealing, or other
150
+ equivalents.
151
+
152
+ 2.7. Conditions
153
+
154
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155
+ in Section 2.1.
156
+
157
+ 3. Responsibilities
158
+ -------------------
159
+
160
+ 3.1. Distribution of Source Form
161
+
162
+ All distribution of Covered Software in Source Code Form, including any
163
+ Modifications that You create or to which You contribute, must be under
164
+ the terms of this License. You must inform recipients that the Source
165
+ Code Form of the Covered Software is governed by the terms of this
166
+ License, and how they can obtain a copy of this License. You may not
167
+ attempt to alter or restrict the recipients' rights in the Source Code
168
+ Form.
169
+
170
+ 3.2. Distribution of Executable Form
171
+
172
+ If You distribute Covered Software in Executable Form then:
173
+
174
+ (a) such Covered Software must also be made available in Source Code
175
+ Form, as described in Section 3.1, and You must inform recipients of
176
+ the Executable Form how they can obtain a copy of such Source Code
177
+ Form by reasonable means in a timely manner, at a charge no more
178
+ than the cost of distribution to the recipient; and
179
+
180
+ (b) You may distribute such Executable Form under the terms of this
181
+ License, or sublicense it under different terms, provided that the
182
+ license for the Executable Form does not attempt to limit or alter
183
+ the recipients' rights in the Source Code Form under this License.
184
+
185
+ 3.3. Distribution of a Larger Work
186
+
187
+ You may create and distribute a Larger Work under terms of Your choice,
188
+ provided that You also comply with the requirements of this License for
189
+ the Covered Software. If the Larger Work is a combination of Covered
190
+ Software with a work governed by one or more Secondary Licenses, and the
191
+ Covered Software is not Incompatible With Secondary Licenses, this
192
+ License permits You to additionally distribute such Covered Software
193
+ under the terms of such Secondary License(s), so that the recipient of
194
+ the Larger Work may, at their option, further distribute the Covered
195
+ Software under the terms of either this License or such Secondary
196
+ License(s).
197
+
198
+ 3.4. Notices
199
+
200
+ You may not remove or alter the substance of any license notices
201
+ (including copyright notices, patent notices, disclaimers of warranty,
202
+ or limitations of liability) contained within the Source Code Form of
203
+ the Covered Software, except that You may alter any license notices to
204
+ the extent required to remedy known factual inaccuracies.
205
+
206
+ 3.5. Application of Additional Terms
207
+
208
+ You may choose to offer, and to charge a fee for, warranty, support,
209
+ indemnity or liability obligations to one or more recipients of Covered
210
+ Software. However, You may do so only on Your own behalf, and not on
211
+ behalf of any Contributor. You must make it absolutely clear that any
212
+ such warranty, support, indemnity, or liability obligation is offered by
213
+ You alone, and You hereby agree to indemnify every Contributor for any
214
+ liability incurred by such Contributor as a result of warranty, support,
215
+ indemnity or liability terms You offer. You may include additional
216
+ disclaimers of warranty and limitations of liability specific to any
217
+ jurisdiction.
218
+
219
+ 4. Inability to Comply Due to Statute or Regulation
220
+ ---------------------------------------------------
221
+
222
+ If it is impossible for You to comply with any of the terms of this
223
+ License with respect to some or all of the Covered Software due to
224
+ statute, judicial order, or regulation then You must: (a) comply with
225
+ the terms of this License to the maximum extent possible; and (b)
226
+ describe the limitations and the code they affect. Such description must
227
+ be placed in a text file included with all distributions of the Covered
228
+ Software under this License. Except to the extent prohibited by statute
229
+ or regulation, such description must be sufficiently detailed for a
230
+ recipient of ordinary skill to be able to understand it.
231
+
232
+ 5. Termination
233
+ --------------
234
+
235
+ 5.1. The rights granted under this License will terminate automatically
236
+ if You fail to comply with any of its terms. However, if You become
237
+ compliant, then the rights granted under this License from a particular
238
+ Contributor are reinstated (a) provisionally, unless and until such
239
+ Contributor explicitly and finally terminates Your grants, and (b) on an
240
+ ongoing basis, if such Contributor fails to notify You of the
241
+ non-compliance by some reasonable means prior to 60 days after You have
242
+ come back into compliance. Moreover, Your grants from a particular
243
+ Contributor are reinstated on an ongoing basis if such Contributor
244
+ notifies You of the non-compliance by some reasonable means, this is the
245
+ first time You have received notice of non-compliance with this License
246
+ from such Contributor, and You become compliant prior to 30 days after
247
+ Your receipt of the notice.
248
+
249
+ 5.2. If You initiate litigation against any entity by asserting a patent
250
+ infringement claim (excluding declaratory judgment actions,
251
+ counter-claims, and cross-claims) alleging that a Contributor Version
252
+ directly or indirectly infringes any patent, then the rights granted to
253
+ You by any and all Contributors for the Covered Software under Section
254
+ 2.1 of this License shall terminate.
255
+
256
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
257
+ end user license agreements (excluding distributors and resellers) which
258
+ have been validly granted by You or Your distributors under this License
259
+ prior to termination shall survive termination.
260
+
261
+ ************************************************************************
262
+ * *
263
+ * 6. Disclaimer of Warranty *
264
+ * ------------------------- *
265
+ * *
266
+ * Covered Software is provided under this License on an "as is" *
267
+ * basis, without warranty of any kind, either expressed, implied, or *
268
+ * statutory, including, without limitation, warranties that the *
269
+ * Covered Software is free of defects, merchantable, fit for a *
270
+ * particular purpose or non-infringing. The entire risk as to the *
271
+ * quality and performance of the Covered Software is with You. *
272
+ * Should any Covered Software prove defective in any respect, You *
273
+ * (not any Contributor) assume the cost of any necessary servicing, *
274
+ * repair, or correction. This disclaimer of warranty constitutes an *
275
+ * essential part of this License. No use of any Covered Software is *
276
+ * authorized under this License except under this disclaimer. *
277
+ * *
278
+ ************************************************************************
279
+
280
+ ************************************************************************
281
+ * *
282
+ * 7. Limitation of Liability *
283
+ * -------------------------- *
284
+ * *
285
+ * Under no circumstances and under no legal theory, whether tort *
286
+ * (including negligence), contract, or otherwise, shall any *
287
+ * Contributor, or anyone who distributes Covered Software as *
288
+ * permitted above, be liable to You for any direct, indirect, *
289
+ * special, incidental, or consequential damages of any character *
290
+ * including, without limitation, damages for lost profits, loss of *
291
+ * goodwill, work stoppage, computer failure or malfunction, or any *
292
+ * and all other commercial damages or losses, even if such party *
293
+ * shall have been informed of the possibility of such damages. This *
294
+ * limitation of liability shall not apply to liability for death or *
295
+ * personal injury resulting from such party's negligence to the *
296
+ * extent applicable law prohibits such limitation. Some *
297
+ * jurisdictions do not allow the exclusion or limitation of *
298
+ * incidental or consequential damages, so this exclusion and *
299
+ * limitation may not apply to You. *
300
+ * *
301
+ ************************************************************************
302
+
303
+ 8. Litigation
304
+ -------------
305
+
306
+ Any litigation relating to this License may be brought only in the
307
+ courts of a jurisdiction where the defendant maintains its principal
308
+ place of business and such litigation shall be governed by laws of that
309
+ jurisdiction, without reference to its conflict-of-law provisions.
310
+ Nothing in this Section shall prevent a party's ability to bring
311
+ cross-claims or counter-claims.
312
+
313
+ 9. Miscellaneous
314
+ ----------------
315
+
316
+ This License represents the complete agreement concerning the subject
317
+ matter hereof. If any provision of this License is held to be
318
+ unenforceable, such provision shall be reformed only to the extent
319
+ necessary to make it enforceable. Any law or regulation which provides
320
+ that the language of a contract shall be construed against the drafter
321
+ shall not be used to construe this License against a Contributor.
322
+
323
+ 10. Versions of the License
324
+ ---------------------------
325
+
326
+ 10.1. New Versions
327
+
328
+ Mozilla Foundation is the license steward. Except as provided in Section
329
+ 10.3, no one other than the license steward has the right to modify or
330
+ publish new versions of this License. Each version will be given a
331
+ distinguishing version number.
332
+
333
+ 10.2. Effect of New Versions
334
+
335
+ You may distribute the Covered Software under the terms of the version
336
+ of the License under which You originally received the Covered Software,
337
+ or under the terms of any subsequent version published by the license
338
+ steward.
339
+
340
+ 10.3. Modified Versions
341
+
342
+ If you create software not governed by this License, and you want to
343
+ create a new license for such software, you may create and use a
344
+ modified version of this License if you rename the license and remove
345
+ any references to the name of the license steward (except to note that
346
+ such modified license differs from this License).
347
+
348
+ 10.4. Distributing Source Code Form that is Incompatible With Secondary
349
+ Licenses
350
+
351
+ If You choose to distribute Source Code Form that is Incompatible With
352
+ Secondary Licenses under the terms of this version of the License, the
353
+ notice described in Exhibit B of this License must be attached.
354
+
355
+ Exhibit A - Source Code Form License Notice
356
+ -------------------------------------------
357
+
358
+ This Source Code Form is subject to the terms of the Mozilla Public
359
+ License, v. 2.0. If a copy of the MPL was not distributed with this
360
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
361
+
362
+ If it is not possible or desirable to put the notice in a particular
363
+ file, then You may include the notice in a location (such as a LICENSE
364
+ file in a relevant directory) where a recipient would be likely to look
365
+ for such a notice.
366
+
367
+ You may add additional accurate notices of copyright ownership.
368
+
369
+ Exhibit B - "Incompatible With Secondary Licenses" Notice
370
+ ---------------------------------------------------------
371
+
372
+ This Source Code Form is "Incompatible With Secondary Licenses", as
373
+ defined by the Mozilla Public License, v. 2.0.
qspylib-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.3
2
+ Name: qspylib
3
+ Version: 0.0.1
4
+ Summary: A set of amateur radio website API wrappers
5
+ Project-URL: Homepage, https://github.com/JayToTheAy/QSPy
6
+ Project-URL: Issues, https://github.com/JayToTheAy/QSPy/issues
7
+ Author-email: Jacob Humble <contact@jacobhumble.com>
8
+ License-File: LICENSE
9
+ Keywords: API,LOTW,QRZ,amateur radio,eQSL
10
+ Classifier: Development Status :: 2 - Pre-Alpha
11
+ Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Requires-Python: >=3.9
15
+ Requires-Dist: adif-io
16
+ Requires-Dist: requests
17
+ Requires-Dist: xmltodict
18
+ Description-Content-Type: text/markdown
19
+
20
+ # QSPyLib
21
+ ![Python Package Build Action Status](https://github.com/JayToTheAy/QSPy/actions/workflows/python-package.yml/badge.svg)
22
+
23
+ QSPyLib is a bundle of API wrappers for various amateur radio-related websites, including QRZ, LOTW, eQSL, and ClubLog.
24
+
25
+ It is currently in development and should be considered unstable version-to-version while the version number is still 0.x.x.
26
+
27
+ Issues and pull requests are welcome, and should be made on the [GitHub repository](https://github.com/jaytotheay/qspy).
28
+
29
+ ## What works right now?
30
+
31
+ As of v0.0.1:
32
+
33
+ * The LotW module is, in theory, finished -- no doubt something will come up about how it's not actually practical and needs more work.
34
+ * The eQSL module has most of the functionality of eQSL's API, but is incredibly unpolished and needs more work.
35
+ * The QRZ module exists; the Logbook API is currently only supported for FETCH operations, and the XML Interface is not supported yet.
36
+ * The ClubLog module is on-hold pending the ready-status of the other modules.
37
+
38
+ ## How do I use it?
39
+
40
+ An example of pulling a Logbook from LOTW:
41
+
42
+ ```py
43
+ from qspylib import lotw
44
+ LOTWAccount = lotw.LOTWSession("callsign", "password")
45
+ logbook = LOTWAccount.fetch_logbook()
46
+ ```
47
+ This will give you a `Logbook` object, which contains a list of QSO objects and a parsed, usable adif_io log. The adif_io log property contains all the ADIF info that LOTW outputs (and likewise for other logging sites); the built-in log property of a `Logbook` object contains only some limited information, like callsign, band, mode, date, time, and QSL status from the originating site (which is a little handy as a single-reference for if a QSO is a QSL, since different sites use different, extra ADIF fields to express being QSL'd on their platform.)
48
+
49
+ Other functions of APIs are generally available, like checking if an eQSL is verified:
50
+
51
+ ```py
52
+ from qspylib import eqsl
53
+ confirmed, raw_result = eqsl.verify_eqsl('N5UP', 'TEST', '160m', 'SSB', '01/01/2000')
54
+ ```
55
+ This will return a tuple; here, `confirmed` will be False, since this QSO is not verified on eQSL, and `raw_result` will contain any extra information eQSL provides, for instance, if it's Authenticity Guaranteed.
56
+
57
+ The best way to find out the functions, methods and objects available is to code dive; an okay-amount-of-effort has been put in to documenting the code with doc strings.
@@ -0,0 +1,38 @@
1
+ # QSPyLib
2
+ ![Python Package Build Action Status](https://github.com/JayToTheAy/QSPy/actions/workflows/python-package.yml/badge.svg)
3
+
4
+ QSPyLib is a bundle of API wrappers for various amateur radio-related websites, including QRZ, LOTW, eQSL, and ClubLog.
5
+
6
+ It is currently in development and should be considered unstable version-to-version while the version number is still 0.x.x.
7
+
8
+ Issues and pull requests are welcome, and should be made on the [GitHub repository](https://github.com/jaytotheay/qspy).
9
+
10
+ ## What works right now?
11
+
12
+ As of v0.0.1:
13
+
14
+ * The LotW module is, in theory, finished -- no doubt something will come up about how it's not actually practical and needs more work.
15
+ * The eQSL module has most of the functionality of eQSL's API, but is incredibly unpolished and needs more work.
16
+ * The QRZ module exists; the Logbook API is currently only supported for FETCH operations, and the XML Interface is not supported yet.
17
+ * The ClubLog module is on-hold pending the ready-status of the other modules.
18
+
19
+ ## How do I use it?
20
+
21
+ An example of pulling a Logbook from LOTW:
22
+
23
+ ```py
24
+ from qspylib import lotw
25
+ LOTWAccount = lotw.LOTWSession("callsign", "password")
26
+ logbook = LOTWAccount.fetch_logbook()
27
+ ```
28
+ This will give you a `Logbook` object, which contains a list of QSO objects and a parsed, usable adif_io log. The adif_io log property contains all the ADIF info that LOTW outputs (and likewise for other logging sites); the built-in log property of a `Logbook` object contains only some limited information, like callsign, band, mode, date, time, and QSL status from the originating site (which is a little handy as a single-reference for if a QSO is a QSL, since different sites use different, extra ADIF fields to express being QSL'd on their platform.)
29
+
30
+ Other functions of APIs are generally available, like checking if an eQSL is verified:
31
+
32
+ ```py
33
+ from qspylib import eqsl
34
+ confirmed, raw_result = eqsl.verify_eqsl('N5UP', 'TEST', '160m', 'SSB', '01/01/2000')
35
+ ```
36
+ This will return a tuple; here, `confirmed` will be False, since this QSO is not verified on eQSL, and `raw_result` will contain any extra information eQSL provides, for instance, if it's Authenticity Guaranteed.
37
+
38
+ The best way to find out the functions, methods and objects available is to code dive; an okay-amount-of-effort has been put in to documenting the code with doc strings.
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "qspylib"
7
+ version = "0.0.1"
8
+ dependencies = [
9
+ "adif_io",
10
+ "requests",
11
+ "xmltodict",
12
+ ]
13
+ requires-python = ">=3.9"
14
+ authors = [
15
+ { name="Jacob Humble", email="contact@jacobhumble.com" },
16
+ ]
17
+ description = "A set of amateur radio website API wrappers"
18
+ readme = "README.md"
19
+ keywords = ["QRZ", "LOTW", "eQSL", "API", "amateur radio"]
20
+ classifiers = [
21
+ "Programming Language :: Python :: 3",
22
+ "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
23
+ "Operating System :: OS Independent",
24
+ "Development Status :: 2 - Pre-Alpha"
25
+ ]
26
+
27
+ [project.urls]
28
+ Homepage = "https://github.com/JayToTheAy/QSPy"
29
+ Issues = "https://github.com/JayToTheAy/QSPy/issues"
Binary file
@@ -0,0 +1,11 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+
5
+ # imports
6
+ from .logbook import QSO, Logbook
7
+ from .lotw import LOTWSession, get_last_upload, upload_logbook
8
+ from .clublog import ClubLogWrapper
9
+ from .qrz import QRZLogbookAPI, QRZXMLInterface
10
+ from .eqsl import eQSLSession, verify_eqsl, retrieve_graphic, get_ag_list, get_ag_list_dated, get_full_member_list, get_users_data
11
+
@@ -0,0 +1,33 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+
5
+ import requests
6
+ from qspylib.logbook import Logbook
7
+
8
+ class ClubLogWrapper:
9
+ """
10
+ API wrapper for ClubLog. At present, only handles fetching QSOs.
11
+ Fetching returns a Logbook object that must be assigned to something.
12
+ """
13
+
14
+ def __init__(self, email: str, callsign: str, password: str):
15
+ self.email = email
16
+ self.callsign = callsign
17
+ self.password = password
18
+ self.base_url = "https://clublog.org/getadif.php"
19
+
20
+ def fetch_logbook(self):
21
+ data = {
22
+ 'email': self.email,
23
+ 'password': self.password,
24
+ 'call': self.callsign
25
+ }
26
+ # filter down to only used params
27
+ data = {k: v for k, v in data.items() if v is not None}
28
+
29
+ response = requests.post(self.base_url, data=data)
30
+ if response.status_code == 200:
31
+ return Logbook(self.callsign, response.text)
32
+ else:
33
+ response.raise_for_status()
@@ -0,0 +1,197 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+
5
+ from qspylib.logbook import Logbook
6
+ import requests
7
+
8
+ # functions that don't require authentication
9
+
10
+ def verify_eqsl(CallsignFrom: str, CallsignTo: str, QSOBand: str, QSOMode: str = None, QSODate: str = None, timeout: int = 15):
11
+ """
12
+ Verify a QSL with eQSL. Returns a tuple containing a Boolean of whether the QSO was verified, and the result str with any extra information.
13
+
14
+ Keyword arguments:
15
+
16
+ CallsignFrom -- Callsign originating QSO (i.e. N5UP)
17
+ CallsignTo -- Callsign receiving QSO (i.e. TEST)
18
+ QSOBand -- Band QSO took place on (i.e. 160m)
19
+ QSOMode -- Mode QSO took place with (i.e. SSB)
20
+ QSODate -- Date QSO took place (i.e. 01/31/2000)
21
+ """
22
+ url = "https://www.eqsl.cc/qslcard/VerifyQSO.cfm"
23
+ params = {
24
+ 'CallsignFrom': CallsignFrom,
25
+ 'CallsignTo': CallsignTo,
26
+ 'QSOBand': QSOBand,
27
+ 'QSOMode': QSOMode,
28
+ 'QSODate': QSODate,
29
+ }
30
+
31
+ with requests.Session() as s:
32
+ r = s.get(url, params=params, headers={'user-agent': 'pyQSP/0.0.1'}, timeout=timeout)
33
+ if r.status_code == 200:
34
+ raw_result = r.text
35
+ if 'Result - QSO on file' in raw_result:
36
+ return True, raw_result
37
+ elif 'Parameter missing' not in raw_result:
38
+ return False, raw_result
39
+ else:
40
+ raise Exception(raw_result)
41
+ else:
42
+ r.raise_for_status()
43
+
44
+ def retrieve_graphic():
45
+ raise NotImplementedError
46
+
47
+ def get_ag_list(timeout: int = 15):
48
+ """Get a list of Authenticity Guaranteed members. Tuple contains a list of string callsigns, and a string header with the date the list was generated."""
49
+
50
+ url = "https://www.eqsl.cc/qslcard/DownloadedFiles/AGMemberList.txt"
51
+
52
+ with requests.Session() as s:
53
+ r = s.get(url, headers={'user-agent': 'pyQSP/0.0.1'}, timeout=timeout)
54
+ if r.status_code == 200:
55
+ result_list = list()
56
+ result_list += r.text.split('\r\n')
57
+ return set(result_list[1:-1]), str(result_list[0])
58
+ else:
59
+ r.raise_for_status()
60
+
61
+ def get_ag_list_dated(timeout: int = 15):
62
+ """
63
+ Get a list of Authenticity Guaranteed eQSL members with the date of their last upload to eQSL.
64
+ Returns a tuple. First element is a dict with key: callsign and value: date, and second is a header of when this list was generated.
65
+ """
66
+ url = "https://www.eqsl.cc/qslcard/DownloadedFiles/AGMemberListDated.txt"
67
+
68
+ with requests.Session() as s:
69
+ r = s.get(url, headers={'user-agent': 'pyQSP/0.0.1'}, timeout=timeout)
70
+ if r.status_code == 200:
71
+ result_list = r.text.split('\r\n')
72
+ loc, header = result_list[1:-1], str(result_list[0])
73
+ dict_calls = dict()
74
+ for pair in loc:
75
+ call, date = pair.split(', ')
76
+ dict_calls[call] = date
77
+ return dict_calls, header
78
+ else:
79
+ r.raise_for_status()
80
+
81
+ def get_full_member_list(timeout: int = 15):
82
+ """Get a list of all members of QRZ. Returns a dict, where the key is the callsign and the value is a tuple of: GridSquare, AG, Last Upload"""
83
+
84
+ url = "https://www.eqsl.cc/DownloadedFiles/eQSLMemberList.csv"
85
+
86
+ with requests.Session() as s:
87
+ r = requests.get(url, timeout=timeout)
88
+ if r.status_code == 200:
89
+ result_list = r.text.split('\r\n')[1:-1]
90
+ dict_calls = dict()
91
+ for row in result_list:
92
+ data = row.split(',')
93
+ dict_calls[data[0]] = data[1:]
94
+ return dict_calls
95
+ else:
96
+ r.raise_for_status()
97
+
98
+ def get_users_data(callsign: str, timeout: int = 15):
99
+ """
100
+ Returns a dict of data on a QRZ user, in the form of: GridSquare, AG, Last Upload
101
+ Note: Slow. Would be faster with vectorization, but then we'd need dependencies.
102
+ """
103
+ dict_users: dict = get_full_member_list()
104
+ return dict_users.get(callsign)
105
+
106
+
107
+ # things that require authentication
108
+ class eQSLSession:
109
+ """
110
+ API wrapper for eQSL. At present, only handles fetching inbox QSOs.
111
+ Fetching returns a Logbook object that must be assigned to something.
112
+ """
113
+
114
+ def __init__(self, username: str, password: str, QTHNickname: str = None, timeout: int = 15):
115
+ self.callsign = username,
116
+ self.timeout = timeout
117
+ self.base_url = "https://www.eqsl.cc/qslcard/"
118
+
119
+ session = requests.Session()
120
+
121
+ session.params = {k: v for k, v in {
122
+ 'username': username,
123
+ 'password': password,
124
+ 'QTHNickname': QTHNickname }.items() if v is not None}
125
+
126
+ session.headers = {'User-Agent': 'pyQSP/0.0.1'}
127
+ self.session = session
128
+
129
+ def set_timeout(self, timeout: int):
130
+ self.timeout = timeout
131
+
132
+ # actual GETs
133
+
134
+ def get_last_upload_date(self):
135
+ " Returns a string with the date of last upload for the active user. Date is formatted: DD-MMM-YYYY at HH:mm UTC"
136
+
137
+ with self.session as s:
138
+ r = s.get(self.base_url + 'DisplayLastUploadDate.cfm', timeout=self.timeout)
139
+ if r.status_code == 200:
140
+ success_txt = 'Your last ADIF upload was'
141
+ if success_txt in r.text:
142
+ return r.text[r.text.index('(')+1:r.text.index(')')]
143
+ else:
144
+ raise Exception(r.text)
145
+
146
+ def fetch_inbox(self, LimitDateLo=None, LimitDateHi=None, RcvdSince=None, ConfirmedOnly=None, UnconfirmedOnly=None, Archive=None, HamOnly=None):
147
+ params = {
148
+ 'LimitDateLo': LimitDateLo,
149
+ 'LimitDateHi': LimitDateHi,
150
+ 'RcvdSince': RcvdSince,
151
+ 'ConfirmedOnly': ConfirmedOnly,
152
+ 'UnconfirmedOnly': UnconfirmedOnly,
153
+ 'Archive': Archive,
154
+ 'HamOnly': HamOnly
155
+ }
156
+ # filter down to only used params
157
+ params = {k: v for k, v in params.items() if v is not None}
158
+
159
+ with self.session as s:
160
+ r = s.get(self.base_url + "DownloadInBox.cfm", params=params, timeout=self.timeout)
161
+ if r.status_code == 200:
162
+ adif_found_txt = 'Your ADIF log file has been built'
163
+ adif_status = r.text.index(adif_found_txt) if adif_found_txt in r.text else -1
164
+ if adif_status < 0:
165
+ raise Exception('Failed to generate ADIF.')
166
+ adif_link_start_idx = r.text.index('<LI><A HREF="..') + 15
167
+ adif_link_end_idx = r.text.index('">.ADI file</A>')
168
+ adif_link = self.base_url + r.text[adif_link_start_idx:adif_link_end_idx]
169
+ adif_response = requests.get(adif_link)
170
+ if adif_response.status_code == 200:
171
+ return Logbook(self.callsign, adif_response.text)
172
+ else:
173
+ r.raise_for_status()
174
+ else:
175
+ r.raise_for_status()
176
+
177
+ def fetch_outbox(self):
178
+ # TO-DO: test
179
+ with self.session as s:
180
+ r = s.get(self.base_url + "DownloadADIF.cfm", timeout=self.timeout)
181
+ if r.status_code == 200:
182
+ adif_found_txt = 'Your ADIF log file has been built'
183
+ adif_status = r.text.index(adif_found_txt) if adif_found_txt in r.text else -1
184
+ if adif_status < 0:
185
+ raise Exception('Failed to generate ADIF.')
186
+ adif_link_start_idx = r.text.index('<LI><A HREF="..') + 15
187
+ adif_link_end_idx = r.text.index('">.ADI file</A>')
188
+ adif_link = self.base_url + r.text[adif_link_start_idx:adif_link_end_idx]
189
+ adif_response = requests.get(adif_link)
190
+ if adif_response.status_code == 200:
191
+ return Logbook(self.callsign, adif_response.text)
192
+ else:
193
+ r.raise_for_status()
194
+ else:
195
+ r.raise_for_status()
196
+
197
+
@@ -0,0 +1,51 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+
5
+ import adif_io
6
+
7
+ class QSO:
8
+ """
9
+ A hambaseio QSO obj. Contains simple info on a QSO.
10
+ """
11
+ def __init__(self, their_call, band, mode, qso_date, time_on, qsl_rcvd='N'):
12
+ self.their_call = their_call
13
+ self.band = band
14
+ self.mode = mode
15
+ self.qso_date = qso_date
16
+ self.time_on = time_on
17
+ self.qsl_rcvd = qsl_rcvd
18
+
19
+ def __str__(self):
20
+ return f"CALL: {self.their_call} BAND: {self.band} MODE: {self.mode} DATE: {self.qso_date} TIME: {self.time_on} QSL: {self.qsl_rcvd}\n"
21
+ # to-do: make this return as an actual adif formattede string
22
+
23
+ class Logbook:
24
+ """
25
+ A Logbook has both an adi field, holding all fields parsed from an .adi log per QSO, and a simplified log field, holding a simplified set of fields per QSO.
26
+ Interacting with the log field can provide one field to check for if a QSO is confirmed on one or more of: LoTW, eQSL, QRZ, or ClubLog.
27
+ """
28
+
29
+ def __init__(self, callsign: str, unparsed_log: str):
30
+ self.callsign = callsign
31
+ self.adi, self.header = adif_io.read_from_string(unparsed_log)
32
+ self.log = set()
33
+ for contact in self.adi:
34
+ # whether this qsl has been confirmed; lotw & clublog use qsl_rcvd, eqsl uses eqsl_qsl_rcvd, qrz most simply gives a qsl date
35
+ qsl_rcvd, qrz_qsl_dte, eqsl_qsl_rcvd = contact.get('QSL_RCVD'), contact.get('app_qrzlog_qsldate'), contact.get('eqsl_qsl_rcvd')
36
+ qso_confirmed = 'Y' if qsl_rcvd == 'Y' or qrz_qsl_dte or eqsl_qsl_rcvd == 'Y' else 'N'
37
+ # create a QSO for this contact
38
+ self.log.add(QSO(contact['CALL'], contact['BAND'], contact['MODE'], contact['QSO_DATE'], contact['TIME_ON'], qso_confirmed))
39
+
40
+ def __str__(self):
41
+ log_str = ""
42
+ for qso in self.log:
43
+ log_str += str(qso)
44
+ return log_str
45
+
46
+ def write_qso(self, contact: QSO):
47
+ self.log.add(contact)
48
+
49
+ def discard_qso(self, contact: QSO):
50
+ self.log.discard(contact)
51
+ # to-do: discrad from adi?
@@ -0,0 +1,158 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+
5
+ import requests
6
+ from qspylib.logbook import Logbook
7
+
8
+ # exceptions
9
+
10
+ class RetrievalFailure(Exception):
11
+ def __init__(self, message="Failed to retrieve information. Confirm log-in credentials are correct."):
12
+ self.message=message
13
+ super().__init__(self, message)
14
+
15
+ class UploadFailure(Exception):
16
+ def __init__(self, message="Failed to upload file."):
17
+ self.message=message
18
+ super().__init__(self, message)
19
+
20
+ # functions
21
+
22
+ def get_last_upload(timeout: int = 15):
23
+ """Queries LOTW for a list of callsigns and date they last uploaded. Returns a csv."""
24
+
25
+ url = 'https://lotw.arrl.org/lotw-user-activity.csv'
26
+
27
+ with requests.Session() as s:
28
+ response = s.get(url, timeout=timeout)
29
+ if response.status_code == 200:
30
+ return response.text
31
+ else:
32
+ response.raise_for_status()
33
+
34
+ def upload_logbook(file, timeout:int=120):
35
+ """
36
+ Given a .tq5 or .tq8, uploads it to LOTW. Throws an error for a connection error or if a file is rejected by LOTW, and gives the error.
37
+ Returns the upload result message, if any.
38
+ TO-DO: Test this actually works.
39
+ """
40
+
41
+ upload_url = "https://lotw.arrl.org/lotw/upload"
42
+
43
+ data = {'upfile': file}
44
+
45
+ with requests.Session() as s:
46
+ response = s.post(upload_url, data, timeout=timeout)
47
+ if response.status_code == 200:
48
+ result = response.text
49
+ result_start_idx = result.index('<!-- .UPL. ')
50
+ result_end_idx = result[result_start_idx + 11:].index(' -->')
51
+ upl_result = result[result_start_idx:result_end_idx]
52
+ upl_message = str(result[result.index('<!-- .UPLMESSAGE. ') + 18:result[result_end_idx:].rindex(' -->')])
53
+ if 'rejected' in upl_result:
54
+ raise UploadFailure(upl_message)
55
+ else:
56
+ return upl_message
57
+ else:
58
+ response.raise_for_status()
59
+
60
+ class LOTWSession:
61
+ """
62
+ Wrapper for LOTW API functionality that requires a logged-in session.
63
+ Fetching returns a Logbook object that must be assigned to something.
64
+ """
65
+
66
+ def __init__(self, username: str, password: str):
67
+ self.username = username
68
+ self.password = password
69
+ self.base_url = "https://lotw.arrl.org/lotwuser/"
70
+
71
+ session = requests.Session()
72
+ session.params = {'login': username,
73
+ 'password': password }
74
+ session.headers = {'User-Agent': 'pyQSP/0.0.1'}
75
+
76
+ self.session = session
77
+
78
+ def fetch_logbook(self, qso_query=1, qso_qsl='yes', qso_qslsince=None, qso_qsorxsince=None, qso_owncall=None,
79
+ qso_callsign=None,qso_mode=None,qso_band=None,qso_dxcc=None,qso_startdate=None, qso_starttime=None,
80
+ qso_enddate=None, qso_endtime=None, qso_mydetail=None,qso_qsldetail=None, qsl_withown=None):
81
+ """
82
+ Fetch a logbook from LOTW.
83
+
84
+ Keyword arguments:
85
+
86
+ qso_query -- If absent, ADIF file will contain no QSO records (default 1)
87
+ qso_qsl -- opt, If "yes", only QSL records are returned (can be 'yes' or 'no', default 'yes')
88
+ qso_qslsince -- opt, QSLs since specified datetime (YYYY-MM-DD HH:MM:SS). Ignored unless qso_qsl="yes".
89
+ qso_qsorxsince -- opt, QSOs received since specified datetime. Ignored unless qso_qsl="no".
90
+ qso_owncall -- opt, returns records where "own" call sign matches
91
+ qso_callsign -- opt, returns records where "worked" call sign matches
92
+ qso_mode -- opt, returns records where mode matches
93
+ qso_band -- opt, returns records where band matches
94
+ qso_dxcc -- opt, returns matching DXCC entities, implies qso_qsl='yes'
95
+ qso_startdate -- opt, Returns only records with a QSO date on or after the specified value.
96
+ qso_starttime -- opt, Returns only records with a QSO time at or after the specified value on the starting date. This value is ignored if qso_startdate is not provided.
97
+ qso_enddate -- opt, Returns only records with a QSO date on or before the specified value.
98
+ qso_endtime -- opt, Returns only records with a QSO time at or before the specified value on the ending date. This value is ignored if qso_enddate is not provided.
99
+ qso_mydetail -- opt, If "yes", returns fields that contain the Logging station's location data, if any.
100
+ qso_qsldetail -- opt, If "yes", returns fields that contain the QSLing station's location data, if any.
101
+ qsl_withown -- opt, If "yes", each record contains the STATION_CALLSIGN and APP_LoTW_OWNCALL fields to identify the "own" call sign used for the QSO.
102
+ """
103
+ log_url = "lotwreport.adi"
104
+
105
+ params = {
106
+ 'qso_query': qso_query,
107
+ 'qso_qsl' : qso_qsl,
108
+ 'qso_qslsince': qso_qslsince,
109
+ 'qso_qsorxsince': qso_qsorxsince,
110
+ 'qso_owncall': qso_owncall,
111
+ 'qso_callsign': qso_callsign,
112
+ 'qso_mode': qso_mode,
113
+ 'qso_band': qso_band,
114
+ 'qso_dxcc': qso_dxcc,
115
+ 'qso_startdate': qso_startdate,
116
+ 'qso_starttime': qso_starttime,
117
+ 'qso_enddate': qso_enddate,
118
+ 'qso_endtime': qso_endtime,
119
+ 'qso_mydetail': qso_mydetail,
120
+ 'qso_qsldetail': qso_qsldetail,
121
+ 'qsl_withown': qsl_withown
122
+ }
123
+ # filter down to only used params
124
+ params = {k: v for k, v in params.items() if v is not None}
125
+
126
+ with self.session as s:
127
+ response = s.get(self.base_url + log_url, params=params)
128
+ if '<eoh>' not in response.text:
129
+ raise RetrievalFailure
130
+ if response.status_code == 200:
131
+ return Logbook(self.username, response.text)
132
+ else:
133
+ response.raise_for_status()
134
+
135
+ def get_dxcc_credit(self, entity:str=None, ac_acct:str=None):
136
+ """
137
+ Gets DXCC award account credit, optionally for a specific DXCC Entity Code specified via entity.
138
+ Note: This only returns *applied for and granted credit*, not 'presumed' credits.
139
+ """
140
+ dxcc_url = "logbook/qslcards.php"
141
+ params = {
142
+ 'entity': entity,
143
+ 'ac_acct': ac_acct
144
+ }
145
+ # filter down to only used params
146
+ params = {k: v for k, v in params.items() if v is not None}
147
+
148
+ with self.session as s:
149
+ response = s.get(self.base_url + dxcc_url, params=params)
150
+ if response.status_code == 200:
151
+ # lotw lies, and claims an <eoh> will be absent from bad outputs, but it's there, so we'll do something else.
152
+ if 'ARRL Logbook of the World DXCC QSL Card Report' not in response.text[:46]:
153
+ raise RetrievalFailure(response.text)
154
+ else:
155
+ return Logbook(self.username, response.text)
156
+ else:
157
+ response.raise_for_status()
158
+
@@ -0,0 +1,111 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+
5
+ import requests
6
+ import html
7
+ import xmltodict
8
+ from qspylib.logbook import Logbook
9
+
10
+ class QRZInvalidSession(Exception):
11
+ def __init__(self, message="Got no session key back. This session is invalid."):
12
+ self.message=message
13
+ super().__init__(self, message)
14
+
15
+
16
+
17
+ class QRZLogbookAPI:
18
+ """
19
+ API wrapper for a QRZ Logbook. At present, only handles fetching QSOs.
20
+ Fetching returns a Logbook object that must be assigned to something.
21
+ """
22
+
23
+ def __init__(self, key: str):
24
+ self.key = key
25
+ self.base_url = "https://logbook.qrz.com/api"
26
+ self.headers = {
27
+ 'User-Agent': 'pyQSP/0.0.1',
28
+ 'Accept-Encoding': 'gzip, deflate',
29
+ 'Accept': '*/*',
30
+ 'Connection': 'keep-alive'
31
+ }
32
+
33
+ def fetch_logbook(self):
34
+ params = {
35
+ 'KEY': self.key,
36
+ 'ACTION': 'FETCH',
37
+ 'OPTION': ''
38
+ }
39
+ # filter down to only used params
40
+ params = {k: v for k, v in params.items() if v is not None}
41
+
42
+ response = requests.get(self.base_url, params=params, headers=self.headers)
43
+ if response.status_code == 200:
44
+ return QRZLogbookAPI.__stringify(self, response.text)
45
+ else:
46
+ response.raise_for_status()
47
+
48
+ def insert_record(self, adif, option=None):
49
+ raise NotImplementedError
50
+
51
+ def delete_record(self, list_logids: list):
52
+ raise NotImplementedError
53
+
54
+ def check_status(self, list_logids: list):
55
+ raise NotImplementedError
56
+
57
+
58
+
59
+ ### Helpers
60
+
61
+ def __stringify(self, adi_log):
62
+ qrz_output = html.unescape(adi_log)
63
+ start_of_log, end_of_log = qrz_output.index('ADIF=') + 5, qrz_output.rindex('<eor>\n\n') + 4
64
+ log_adi = "<EOH>" + qrz_output[start_of_log:end_of_log] #adif_io expects a header, so we're giving it an end of header
65
+ return Logbook(self.key, log_adi)
66
+
67
+ class QRZXMLInterface:
68
+ """
69
+ A wrapper for the QRZ XML interface.
70
+ This functionality requires being logged in and maintaining a session.
71
+ """
72
+
73
+ def __init__(self, username:str=None, password:str=None):
74
+ self.username = username,
75
+ self.password = password,
76
+ self.agent = 'pyQSP/0.0.1'
77
+ self.session_key = None
78
+ self.base_url = "https://xmldata.qrz.com/xml/1.34/"
79
+ self.headers = {
80
+ 'User-Agent': self.agent,
81
+ 'Accept-Encoding': 'gzip, deflate',
82
+ 'Accept': '*/*',
83
+ 'Connection': 'keep-alive'
84
+ }
85
+
86
+ self.__initiate_session()
87
+
88
+ def __initiate_session(self):
89
+ """Helper -- Grab us a session key so we're not throwing around passwords"""
90
+ params = {'username': self.username,
91
+ 'password': self.password,
92
+ 'agent': self.agent}
93
+
94
+ response = requests.get(self.base_url, params=params, headers=self.headers)
95
+ xml_dict = xmltodict.parse(response.text)
96
+ key = xml_dict["QRZDatabase"]["Session"].get("Key")
97
+ if not key:
98
+ raise QRZInvalidSession()
99
+ else:
100
+ self.session_key = key
101
+
102
+ def __verify_session(self):
103
+ """ Helper -- Verify our session key is still valid."""
104
+ params = {'agent': self.agent,
105
+ 's': self.session_key}
106
+
107
+ response = requests.get(self.base_url, params=params, headers=self.headers)
108
+ if not xmltodict.parse(response.text)["QRZDatabase"]["Session"].get("Key"):
109
+ raise QRZInvalidSession()
110
+
111
+
@@ -0,0 +1,71 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+
5
+ import pytest
6
+ import qspylib.eqsl as eqsl
7
+ import qspylib.lotw as lotw
8
+ import qspylib.qrz as qrz
9
+
10
+ ##############
11
+ # lotw tests #
12
+ ##############
13
+
14
+ def test_pull_a_call_from_last_upload():
15
+ last_uploads = lotw.get_last_upload()
16
+ assert 'W1AW' in last_uploads
17
+
18
+ def test_bad_login_fetch():
19
+ with pytest.raises(lotw.RetrievalFailure):
20
+ lotw_obj = lotw.LOTWSession('**notavalidcall**', '**notarealpassword**')
21
+ lotw_obj.fetch_logbook()
22
+
23
+ def test_bad_login_dxcc():
24
+ with pytest.raises(lotw.RetrievalFailure):
25
+ lotw_obj = lotw.LOTWSession('**notavalidcall**', '**notarealpassword**')
26
+ lotw_obj.get_dxcc_credit()
27
+
28
+ ###############
29
+ # eqsl tests #
30
+ ###############
31
+
32
+ def test_verify_a_bad_eqsl():
33
+ is_qsl_real, result = eqsl.verify_eqsl('N5UP', 'TEST', '160m', 'SSB', '01/01/2000')
34
+ assert 'Error - Result: QSO not on file' in result and is_qsl_real is False
35
+
36
+ def test_verify_a_good_eqsl():
37
+ is_qsl_real, result = eqsl.verify_eqsl('ai5zk', 'w1tjl', '10m', 'SSB', '01/20/2024')
38
+ assert 'Result - QSO on file' in result and is_qsl_real is True
39
+
40
+ def test_pull_a_known_ag_call():
41
+ callsigns, date = eqsl.get_ag_list()
42
+ assert 'W1AW' in callsigns
43
+
44
+ def test_pull_a_known_nonag_call():
45
+ callsigns, date = eqsl.get_ag_list()
46
+ assert 'WE3BS' not in callsigns
47
+
48
+ def test_pull_a_call_from_ag_dated():
49
+ callsigns, date = eqsl.get_ag_list_dated()
50
+ assert callsigns.get('W1AW') >= '0000-00-00'
51
+
52
+ def test_pull_a_known_call_from_total_members():
53
+ all_users = eqsl.get_full_member_list()
54
+ assert all_users.get('W1AW')
55
+
56
+ def test_pull_a_missing_call_from_total_members():
57
+ all_users = eqsl.get_full_member_list()
58
+ assert not all_users.get('WE3BS')
59
+
60
+ def test_get_user_data():
61
+ user = eqsl.get_users_data('W1AW')
62
+ assert user[0] == 'FN31pr' and user[1] == 'Y' and not user[2]
63
+
64
+ #############
65
+ # qrz tests #
66
+ #############
67
+
68
+ #def test_qrz_xml_with_invalid_key():
69
+ # log_obj = qrz.QRZLogbookAPI('aaaaaaaaaaaaa')
70
+ # log = log_obj.fetch_logbook()
71
+