Last active
March 23, 2022 09:17
-
-
Save quamilek/6f658b6a77f634807bbc2409fbcd96f1 to your computer and use it in GitHub Desktop.
Export CSV from sotadata.com to ADI log file
This file contains 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 sys | |
# how to use: | |
# | |
# run command: | |
# $ python3 convert_CSV_2_ADI.py input_file.csv exported_log.adi | |
# | |
# CSV file row should be in format | |
# | |
# V2,OPERATOR_CALLSIGN,COMMENT,25/10/2020,12:35,3.5MHz,SSB,CALLSIGN,, | |
# | |
def convert_csv_2_adi(filename, exported_filename): | |
log_header = """ | |
<ADIF_VER:5>3.1.1 | |
<PROGRAMID:14>SP3WKW_CSV2ADI | |
<PROGRAMVERSION:3>0.1 | |
<eoh> | |
""" | |
default_rst_rcv = "59" | |
default_rst_sent = "59" | |
adif_log_rows = "" | |
adif_log_rows += log_header | |
with open(filename) as logfile: | |
log_lines = logfile.readlines() | |
log_row = log_lines[0] | |
for log_row in log_lines: | |
_, operator, comment, date, time, freq, mode, call, _, _ = log_row.split(',') | |
day, month, year = date.split('/') | |
converted_date = f'{year}{month}{day}' | |
hour, minute = time.split(':') | |
converted_time = f'{hour}{minute}' | |
adif_log_row = f''' | |
<call:{len(call)}>{call} | |
<freq:{len(freq)}>{freq} | |
<mode:{len(mode)}>{mode} | |
<operator:{len(operator)}>{operator} | |
<qso_date:{len(converted_date)}>{converted_date} | |
<rst_rcvd:{len(default_rst_rcv)}>{default_rst_rcv} | |
<rst_sent:{len(default_rst_sent)}>{default_rst_sent} | |
<time_on:{len(converted_time)}>{converted_time} | |
<comment:{len(comment)}>{comment} | |
<eor> | |
''' | |
adif_log_rows += adif_log_row | |
print(f'Export finished') | |
print(f'Exported {len(log_lines)} QSO\'s to {exported_filename} file') | |
with open(exported_filename, 'w') as ff: | |
ff.write(adif_log_rows) | |
def main(): | |
convert_csv_2_adi(sys.argv[1], sys.argv[2]) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment