forked from k0swe/dxcc-json
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdxcc.py
37 lines (28 loc) · 1.03 KB
/
dxcc.py
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
import csv
import json
def getEntityCode(e):
return e['entityCode']
dxccList = []
with open('dxcc-2020-02.csv', mode='r', encoding='utf8') as infile:
reader = csv.DictReader(infile)
for row in reader:
row['entityCode'] = int(row['entityCode'])
row['deleted'] = (row['deleted'] == 'Y')
row['outgoingQslService'] = (row['outgoingQslService'] == 'Y')
row['thirdPartyTraffic'] = (row['thirdPartyTraffic'] == 'Y')
# Continent must be an array for Maldives and Turkey
temp = row['continent'].split(',')
row['continent'] = []
for c in temp:
row['continent'].append(c.strip())
temp = row['itu'].split(',')
row['itu'] = []
for c in temp:
row['itu'].append(int(c.strip()))
temp = row['cq'].split(',')
row['cq'] = []
for c in temp:
row['cq'].append(int(c.strip()))
dxccList.append(row)
dxccList.sort(key=getEntityCode)
print(json.dumps({'dxcc': dxccList}, ensure_ascii=False, sort_keys=True))