-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_json.py
More file actions
executable file
·35 lines (30 loc) · 1.17 KB
/
make_json.py
File metadata and controls
executable file
·35 lines (30 loc) · 1.17 KB
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
#!/usr/bin/env python
import re
import json
import collections
def get_fields(adif_file, field_name):
adif_fh = open(adif_file, 'r')
log = adif_fh.readlines()
pattern = re.compile('^.*<' + field_name + ':\d+>([^<]*)<.*$', re.IGNORECASE)
matches = [re.match(pattern, line) for line in log]
adif_fh.seek(0)
return [line[1].strip() for line in matches if line is not None]
calls = collections.defaultdict(dict)
adif = {}
for country in ['ES', 'YL', 'LY']:
adif[country] = {}
for item in ['call', 'band', 'mode']:
adif[country][item + 's'] = get_fields(country + '30WAY.adi', item)
for participant in adif[country]['calls']:
if participant not in calls.keys():
calls[participant] = {}
calls[participant][country] = collections.defaultdict(list)
qso_index = [i for i, x in enumerate(adif[country]['calls']) if x == participant]
for qso in qso_index:
calls[participant][country][adif[country]['bands'][qso]].append(
adif[country]['modes'][qso]
)
json_data = json.dumps(calls, indent=2)
json_file = open("statistics.json", "w+")
json_file.write(json_data)
json_file.close()