Skip to content
This repository was archived by the owner on Dec 26, 2025. It is now read-only.

Commit 937f9ec

Browse files
committed
Added examples
1 parent 4f5c274 commit 937f9ec

6 files changed

Lines changed: 1023 additions & 0 deletions

File tree

examples/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
PyADIF-File Examples
2+
====================
3+
For all examples it is expected that PyADIF-File is installed properly in the system wide site-packages
4+
and you run Python >= 3.10 as well
5+
6+
# pip install pyadif-file
7+
8+
**Have fun!**
9+
10+
11+
gen_big_adi
12+
-----------
13+
This tool generates huge ADIF files in ADI or ADX format.
14+
This files can be used for performance testing your code.
15+
16+
gen_big_adi.py [NUMBER_QSOS] [-x]
17+
18+
Per default it generates a 1000 QSO sized ADI file
19+
20+
# gen_big_adi.py -x 10000
21+
22+
This will generate a 10000 QSO ADX file.
23+
24+
25+
csv2adi
26+
-------
27+
This tool converts an ADI file to CSV or vice versa.
28+
As CSV field seperator `;` is used.
29+
30+
csv2adi.py [INPUT] [OUTPUT] [-n]
31+
32+
Generate ADI from CSV (use `-n` to omit a header)
33+
34+
# csv2adi.py file.csv file.adi
35+
36+
Generate CSV from ADI
37+
38+
# csv2adi.py file.adi file.csv
39+
40+
41+
nu_plugin_adi
42+
-------------
43+
This one provides a plugin to use ADI format inside [Nushell](https://www.nushell.sh/) easily.
44+
45+
The plugin provides `to adi` and `from adi`.
46+
47+
It's just the start of development so do not be afraid of some misbehaviour.
48+
I learned Nushell just two weeks ago and couldn't resist.
49+
50+
Register plugin in running Nushell
51+
52+
# plugin add ./nu_plugin_adi.py
53+
# plugin use adi
54+
55+
Show the first 10 QSOs from ADI file as table (`from adi` is automatically run from `open` on .adi files)
56+
57+
# open file.adi | first 10
58+
59+
Once information is represented as a table, all Nushell doors are wide open...
60+
61+
Find all QSO with a portable station in ADI, select some columns only
62+
and store them to CSV (using non default separator `;`)
63+
64+
# open file.adi | where CALL =~ "/P" | select QSO_DATE TIME_ON CALL BAND MODE | to csv -s ";" | save file.csv
65+
66+
Convert CSV to ADI (using non default separator `;`)
67+
68+
# open file.csv --raw | from csv -s ";" | to adi | save file.adi
69+
70+
You get it? Be amazed! I am! Totally!

examples/csv2adi.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
import csv
5+
6+
from adif_file import adi
7+
8+
CSV_SEPARATOR = ';'
9+
10+
11+
def csv2adi(csv_file: str, adi_file: str, header=True):
12+
doc = {'RECORDS': []}
13+
if header:
14+
doc['HEADER'] = {}
15+
16+
with open(csv_file) as csv_f:
17+
for row in csv.DictReader(csv_f, delimiter=CSV_SEPARATOR):
18+
doc['RECORDS'].append(row)
19+
20+
adi.dump(adi_file, doc)
21+
22+
23+
def adi2csv(adi_file: str, csv_file: str):
24+
with open(adi_file) as adi_f:
25+
adi_str = adi_f.read()
26+
27+
fieldnames = ['QSO_DATE', 'TIME_ON', 'CALL', 'BAND', 'MODE', 'RST_SENT', 'RST_RCVD']
28+
for i, rec in enumerate(adi.loadi(adi_str)):
29+
if i == 0:
30+
continue
31+
for k in rec.keys():
32+
if k not in fieldnames:
33+
fieldnames.append(k)
34+
35+
with open(csv_file, 'w', newline='') as csv_f:
36+
csv_w = csv.DictWriter(csv_f, fieldnames, delimiter=CSV_SEPARATOR)
37+
csv_w.writeheader()
38+
39+
for i, rec in enumerate(adi.loadi(adi_str)):
40+
if i == 0:
41+
continue
42+
csv_w.writerow(rec)
43+
44+
45+
if __name__ == '__main__':
46+
import os
47+
48+
if len(sys.argv) > 2:
49+
fin = sys.argv.pop(1)
50+
fout = sys.argv.pop(1)
51+
ftype = os.path.splitext(fin)[1]
52+
if not os.path.isfile(fin):
53+
sys.exit(f'Unable to read file "{fin}"')
54+
55+
if ftype == '.csv':
56+
csv2adi(fin, fout, not (len(sys.argv) > 1 and sys.argv[1] == '-n'))
57+
elif ftype == '.adi':
58+
adi2csv(fin, fout)
59+
else:
60+
sys.exit(f'Unable to determin filetype from extension "{ftype}".\nUse .adi or .csv files only.')
61+
else:
62+
sys.exit(f'Requires an .adi or .csv file as parameter\nUsage: {sys.argv[0]} INPUT OUTPUT [-n]')

examples/data/bands.json

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
{
2+
"2190m": [
3+
135.7,
4+
137.8,
5+
1
6+
],
7+
"630m": [
8+
472.0,
9+
479.0,
10+
1
11+
],
12+
"560m": [
13+
501.0,
14+
504.0,
15+
1
16+
],
17+
"160m": [
18+
1800,
19+
2000,
20+
100
21+
],
22+
"80m": [
23+
3500,
24+
4000,
25+
100
26+
],
27+
"60m": [
28+
5060,
29+
5450,
30+
100
31+
],
32+
"40m": [
33+
7000,
34+
7300,
35+
100
36+
],
37+
"30m": [
38+
10100,
39+
10150,
40+
100
41+
],
42+
"20m": [
43+
14000,
44+
14350,
45+
100
46+
],
47+
"17m": [
48+
18068,
49+
18168,
50+
100
51+
],
52+
"15m": [
53+
21000,
54+
21450,
55+
100
56+
],
57+
"12m": [
58+
24890,
59+
24990,
60+
100
61+
],
62+
"10m": [
63+
28000,
64+
29700,
65+
100
66+
],
67+
"8m": [
68+
40000,
69+
45000,
70+
100
71+
],
72+
"6m": [
73+
50000,
74+
54000,
75+
100
76+
],
77+
"5m": [
78+
54000,
79+
69900,
80+
100
81+
],
82+
"4m": [
83+
70000,
84+
71000,
85+
100
86+
],
87+
"2m": [
88+
144000,
89+
148000,
90+
100
91+
],
92+
"1.25m": [
93+
222000,
94+
225000,
95+
100
96+
],
97+
"70cm": [
98+
420000,
99+
450000,
100+
100
101+
],
102+
"33cm": [
103+
902000,
104+
928000,
105+
100
106+
],
107+
"23cm": [
108+
1240000,
109+
1300000,
110+
100
111+
],
112+
"13cm": [
113+
2300000,
114+
2450000,
115+
100
116+
],
117+
"9cm": [
118+
3300000,
119+
3500000,
120+
100
121+
],
122+
"6cm": [
123+
5650000,
124+
5925000,
125+
100
126+
],
127+
"3cm": [
128+
10000000,
129+
10500000,
130+
100
131+
],
132+
"1.25cm": [
133+
24000000,
134+
24250000,
135+
100
136+
],
137+
"6mm": [
138+
47000000,
139+
47200000,
140+
100
141+
],
142+
"4mm": [
143+
75500000,
144+
81000000,
145+
100
146+
],
147+
"2.5mm": [
148+
119980000,
149+
123000000,
150+
100
151+
],
152+
"2mm": [
153+
134000000,
154+
149000000,
155+
100
156+
],
157+
"1mm": [
158+
241000000,
159+
250000000,
160+
100
161+
],
162+
"submm": [
163+
300000000,
164+
7500000000,
165+
100
166+
]
167+
}

0 commit comments

Comments
 (0)