Created
June 6, 2018 03:36
-
-
Save amicuscertus/6bf97bb7ffe2b31b3bd3aef348b3b44a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import datetime | |
fnames = ['station1.adif', 'station2.adif'] | |
def parse_adif(fn): | |
raw = re.split('<eor>|<eoh>',open(fn).read() ) | |
raw.pop(0) | |
raw.pop() | |
logbook =[] | |
for record in raw: | |
qso = {} | |
tags = re.findall('<(.*?):\d+.*?>([^<\t\n\r\f\v]+)',record) | |
for tag in tags: | |
qso[tag[0]] = tag[1] | |
logbook.append(qso) | |
return logbook | |
def mydatetime(date, time): | |
dt = datetime.datetime(int(date[0:4]), int(date[4:6]), int(date[6:8]), \ | |
int(time[0:2]), int(time[2:4]), int(time[4:6])) | |
return dt | |
dt0 = datetime.datetime(2018, 6, 5, 9, 10, 44) | |
dt9 = datetime.datetime(2018, 6, 9, 23, 59, 59) | |
pattern1 = r"10" | |
pattern2 = r"Japan" | |
fcount = 0 | |
for fn in fnames: | |
log = parse_adif(fn) | |
scount = 0 | |
for qso in log: | |
if ('FREQ' in qso and re.match(pattern1, qso['FREQ' ])) and \ | |
('COUNTRY' in qso and re.match(pattern2, qso['COUNTRY'])): | |
dt = mydatetime(qso['QSO_DATE'], qso['TIME_ON']) | |
if dt >= dt0 and dt <=dt9: | |
td = dt - dt0 | |
print(fcount, td.total_seconds()/3600.0, scount) | |
scount += 1 | |
fcount += 1 | |
# end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment