-
Notifications
You must be signed in to change notification settings - Fork 0
/
wwara-to-chirp-csv
executable file
·106 lines (98 loc) · 3.22 KB
/
wwara-to-chirp-csv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python2
from csv import QUOTE_ALL, DictReader, DictWriter
from decimal import Decimal
from sys import stdout
from zipfile import ZipFile
import requests
from StringIO import StringIO
fieldnames = (
"Location",
"Name",
"Frequency",
"Duplex",
"Offset",
"Tone",
"rToneFreq",
"cToneFreq",
"DtcsCode",
"DtcsPolarity",
"Mode",
"Comment",
)
# 'TStep', 'Skip', 'Comment', 'URCALL', 'RPT1CALL', 'RPT2CALL')
r = requests.get("https://www.wwara.org/DataBaseExtract.zip")
# ZipFile requires a file-like object that supports seek
f = StringIO(r.content)
r.close()
z = ZipFile(f)
def drop_decimals(d):
# Decimal.normalize gives 2E+1 for 20...
d = str(d)
if "." in d:
d = d.rstrip("0").rstrip(".")
return d
for n in z.namelist():
if n.endswith(".csv") and "pending" not in n:
w = DictWriter(stdout, fieldnames)
w.writeheader()
with z.open(n) as c:
# Remove the DATA_SPEC_VERSION header line from the .csv
c.readline()
d = DictReader(c)
i = 0
for row in d:
in_freq = Decimal(row["INPUT_FREQ"])
out_freq = Decimal(row["OUTPUT_FREQ"])
duplex = "off"
offset = Decimal(0)
if out_freq < in_freq:
duplex = "+"
offset = in_freq - out_freq
elif out_freq > in_freq:
duplex = "-"
offset = out_freq - in_freq
tone = None
if row["CTCSS_IN"]:
tone = "Tone"
elif row["DCS_CDCSS"]:
tone = "DTCS"
mode = None
if row["FM_WIDE"] == "Y":
mode = "FM"
elif row["FM_NARROW"] == "Y":
mode = "NFM"
else:
continue
if "Y" in (
row["DSTAR_DV"],
row["DSTAR_DD"],
row["DMR"],
row["FUSION"],
row["P25_PHASE_1"],
row["P25_PHASE_2"],
row["NXDN_DIGITAL"],
row["ATV"],
row["DATV"],
):
# These are not Analog modes
continue
w.writerow(
{
"Location": i,
# 'Name': ' '.join((row['CALL'], row['CITY'])),
"Name": row["CALL"],
"Frequency": row["OUTPUT_FREQ"],
"Duplex": duplex,
"Offset": drop_decimals(offset),
"Tone": tone,
"rToneFreq": row["CTCSS_IN"] or "88.5",
"cToneFreq": row["CTCSS_OUT"] or "88.5",
"DtcsCode": row["DCS_CDCSS"] or "23",
"DtcsPolarity": "NN",
"Mode": mode,
# 'Comment': ' / '.join((row['CITY'], row['LOCALE'],
# row['SPONSOR']))
}
)
i += 1
f.close()