Create a gist now

Instantly share code, notes, and snippets.

@chazapis /wpx.py
Last active Nov 1, 2015

What would you like to do?
Count WPXs in ADIF file.
#!/usr/bin/env python
import sys
import re
import urllib2
# From: http://web.bxhome.org/blog/ok4bx/2012/05/adif-parser-python
def parse_adif(fn):
raw = re.split('<eor>|<eoh>(?i)', open(fn).read())
raw.pop(0) # Remove header.
raw.pop() # Remove last empty item.
logbook = []
for record in raw:
qso = {}
tags = re.findall('<(.*?):(\d+).*?>([\w/]+).*?([\s\Z]+)', record)
for tag in tags:
qso[tag[0].lower()] = tag[2][:int(tag[1])]
logbook.append(qso)
return logbook
if __name__ == '__main__':
if len(sys.argv) != 2:
print 'Usage: %s <ADIF file>' % sys.argv[0]
sys.exit(1)
# Get eQSL AG users.
try:
response = urllib2.urlopen('http://www.eqsl.cc/qslcard/DownloadedFiles/AGMemberList.txt')
eqsl_users = response.read().split('\r\n')
except:
print 'WARNING: Could not get eQSL AG users list. Showing all eQSL WPXs.'
eqsl_users = None
def is_eqsl_ag_user(callsign):
if eqsl_users and callsign not in eqsl_users:
return False
return True
entries = parse_adif(sys.argv[1])
qsl_list = [entry for entry in entries if entry['qsl_rcvd'] == 'Y']
lotw_list = [entry for entry in entries if entry['lotw_qsl_rcvd'] == 'Y']
eqsl_list = [entry for entry in entries if entry['eqsl_qsl_rcvd'] == 'Y']
any_list = [entry for entry in entries if entry['qsl_rcvd'] == 'Y' or
entry['lotw_qsl_rcvd'] == 'Y' or
entry['eqsl_qsl_rcvd'] == 'Y']
all_wpx_set = set([entry['pfx'] for entry in entries])
qsl_wpx_set = set([entry['pfx'] for entry in entries if entry['qsl_rcvd'] == 'Y'])
lotw_wpx_set = set([entry['pfx'] for entry in entries if entry['lotw_qsl_rcvd'] == 'Y'])
eqsl_wpx_set = set([entry['pfx'] for entry in entries if (entry['eqsl_qsl_rcvd'] == 'Y' and is_eqsl_ag_user(entry['call']))])
any_wpx_set = qsl_wpx_set | lotw_wpx_set | eqsl_wpx_set
print '{0:>16s} | {1:^6s} | {2:^6s}'.format('', 'QSOs', 'WPXs')
print '{0:->16s}-+-{1:->6s}-+-{2:->6s}'.format('', '', '')
print '{0:>16s} | {1:6d} | {2:6d}'.format('All', len(entries), len(all_wpx_set))
print '{0:>16s} | {1:6d} | {2:6d}'.format('Confirmed QSL', len(qsl_list), len(qsl_wpx_set))
print '{0:>16s} | {1:6d} | {2:6d}'.format('Confirmed LoTW', len(lotw_list), len(lotw_wpx_set))
print '{0:>16s} | {1:6d} | {2:6d}'.format('Confirmed eQSL', len(eqsl_list), len(eqsl_wpx_set))
print '{0:>16s} | {1:6d} | {2:6d}'.format('Confirmed total', len(any_list), len(any_wpx_set))
Owner

chazapis commented Nov 1, 2015

Updated to count eQSL WPXs only from eQSL AG users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment