Created
February 9, 2013 20:16
-
-
Save rrrodrigo/4746906 to your computer and use it in GitHub Desktop.
converts SOTA chaser ADIF files into CSV suitable for importing into http://database.sota.org.uk/
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
my_call = ARGV[1] | |
adif_file = File.open(ARGV[0], "r").read | |
csv_file = File.open(ARGV[0]+".csv", "a+") | |
body = adif_file.split("<eoh>")[1] | |
reports = body.split("<eor>") | |
reports.pop | |
# csv_header = "My Call,Date,Time,Full reference,Band,Mode,Station worked,Notes\n" | |
# csv_file << csv_header | |
reports.each do |r| | |
rep_hash = {} | |
elements = r.split("<") | |
elements.shift | |
elements.each do |e| | |
k,v = e.split(">") | |
k = k.split(":")[0] | |
rep_hash[k] = v.nil? ? '' : v.gsub("'", "''") | |
end | |
date = "#{rep_hash['qso_date'].strip[6..7]}/#{rep_hash['qso_date'].strip[4..5]}/#{rep_hash['qso_date'].strip[0..3]}" | |
time = "#{rep_hash['time_on'][0..1]}:#{rep_hash['time_on'][2..3]}" | |
summit = (rep_hash['comment'].match /[A-Z]{2}\d*\/[A-Z]{2}-\d{3}/)[0] | |
freq = rep_hash['freq'].to_i | |
freq = 144 if freq == 145 | |
freq = 433 if freq > 433 && freq < 440 | |
band = "#{freq}Mhz" | |
mode = rep_hash['mode'].strip | |
call = rep_hash['call'].strip | |
notes = "#{rep_hash['name'] ? rep_hash['name'].strip : ''} #{rep_hash['rst_sent'].strip}/#{rep_hash['rst_rcvd'].strip}".strip | |
qso = [my_call, date, time, summit, band, mode, call, notes] | |
csv = "#{qso.join(',')}\n" | |
csv_file << csv | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment