#!/usr/bin/env python3 # # SM0KBD 211230 v0.1: First version # # SM0KBD 220105 v0.2: CQRLOG export all MGM as mode 0, chnaged into mode 7 # import tkinter as tk from tkinter import ttk from tkinter.filedialog import askopenfilename import string import re def check_line(line): global square_points global dist_points fixed_line = line selector = line[:5] if selector == "CWWLs": x = fixed_line.rsplit(";") squares = x[0].rsplit("=")[1] points = 500 multi = int(x[2]) square_points = int(squares) * int(points) * int(multi) fixed_line = "CWWLs={!s};{!s};{!s}\n".format(squares, points, multi) elif selector == "PBand": band = fixed_line.rsplit("=")[1] # Bands are standardized so these are bugs in CQRLOG if band[:-1] == "432 MHz": fixed_line = "PBand=435 MHz\n" elif band[:-1] =="144 MHz": fixed_line = "PBand=145 MHz\n" elif selector == "CWWLB": fixed_line = "CWWLB={!s}\n".format(square_points) elif selector == "CQSOP": dist_points = int(fixed_line.rsplit("=")[1]) elif selector == "CToSc": fixed_line = "CToSc={!s}\n".format(square_points + dist_points) elif selector == "[END;": fixed_line = fixed_line.rsplit("]")[0] + " / SM0KBD Conv 0.2]" elif QSOline.match(selector): if re.search(MGMline,fixed_line): # Assume all lines with mode 0 is MGM == 7 mode = re.search(";0;", fixed_line) fixed_line = fixed_line[:mode.start()] + ";7;" + fixed_line[mode.end():] return fixed_line def convert(): # Check if input file has been selected if not 'cqrlogedi' in globals(): tk.messagebox.showerror(title="File missing", message="No input file selected!") return 0 # Do the conversion if cqrlogedi.rfind(".edi") == -1: convertededi = cqrlogedi + ".nac" else: convertededi = cqrlogedi.replace(".edi", ".nac.edi") cqrlog = open(cqrlogedi, "r") converted = open(convertededi, "w") for line in cqrlog: line = check_line(line) converted.write(line) status_text = "File converted to {!s}".format(convertededi[convertededi.rfind("/")+1:]) tk.messagebox.showinfo(title="File converted", message=status_text) cqrlog.close() converted.close() def selectfile(): # Handle the input EDI file selection global cqrlogedi cqrlogedi = askopenfilename() QSOline = re.compile(r"\d{5}") MGMline = re.compile(r"\d{6};\d{4}\;[^;]*;0") # Build a simple interface root = tk.Tk() root.geometry("400x150") root.title("NAC EDI Converter") frame = ttk.Frame(root) frame.pack() label = ttk.Label(frame, text = "Convert a CQRLOG edi file to a NAC edi file", borderwidth=1, justify=tk.CENTER, padding= 5) button1 = ttk.Button(frame, text = "Select CQRLOG edi file", command = selectfile) button1.pack(padx=5, pady=5) button2 = ttk.Button(frame, text = "Convert", command = convert) button2.pack(padx=5, pady=5) button3 = ttk.Button(frame, text = "Exit", command = lambda: root.quit()) button3.pack(padx=5, pady=5) root.mainloop()