rearrange columns
This commit is contained in:
29
main.py
29
main.py
@@ -2,6 +2,7 @@ import re
|
||||
import csv
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog, messagebox
|
||||
import subprocess
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
@@ -46,21 +47,34 @@ def parse_logs(log_text):
|
||||
def write_csv1(pairs, filename):
|
||||
with open(filename, 'w', newline='') as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerow(['WEIGHT', 'UNITS', 'TIMESTAMP'])
|
||||
writer.writerow(['WEIGHT', 'UNITS', 'TIME'])
|
||||
for weight, units, timestamp in pairs:
|
||||
writer.writerow([weight, units, timestamp])
|
||||
|
||||
def write_csv2(pairs, filename):
|
||||
with open(filename, 'w', newline='') as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerow(['GROSS_WEIGHT', 'GROSS_UNITS', 'GROSS_TIME', 'TARE_WEIGHT', 'TARE_UNITS', 'TARE_TIME', 'NET', 'NET_UNITS'])
|
||||
writer.writerow(['GROSS_WT', 'TARE_WT', 'NET_WT', 'TARE_T', 'GROSS_T', 'GROSS_UNITS', 'TARE_UNITS', 'NET_UNITS'])
|
||||
for j in range(0, len(pairs), 2):
|
||||
if j + 1 < len(pairs):
|
||||
gross_weight, gross_units, gross_time = pairs[j]
|
||||
tare_weight, tare_units, tare_time = pairs[j + 1]
|
||||
net = gross_weight - tare_weight
|
||||
# Use gross units for net (assuming consistent units within pairs)
|
||||
writer.writerow([gross_weight, gross_units, gross_time, tare_weight, tare_units, tare_time, net, gross_units])
|
||||
writer.writerow([gross_weight, tare_weight, net, tare_time, gross_time, gross_units, tare_units, gross_units])
|
||||
|
||||
def run_update_script():
|
||||
try:
|
||||
# Run update.sh script
|
||||
result = subprocess.run(['sh', 'C:\\Program Files\\rslugger-merger\\update.sh'], capture_output=True, text=True, cwd=os.getcwd())
|
||||
if result.returncode == 0:
|
||||
messagebox.showinfo("Success", f"update.sh executed successfully!\n\nOutput:\n{result.stdout}")
|
||||
else:
|
||||
messagebox.showerror("Error", f"update.sh failed with return code {result.returncode}\n\nError:\n{result.stderr}")
|
||||
except FileNotFoundError:
|
||||
messagebox.showerror("Error", "update.sh not found in current directory")
|
||||
except Exception as e:
|
||||
messagebox.showerror("Error", f"Failed to run update.sh: {str(e)}")
|
||||
|
||||
def select_input_file():
|
||||
filename = filedialog.askopenfilename(filetypes=[("Text files", "*.txt"), ("All files", "*.*")])
|
||||
@@ -91,7 +105,7 @@ def process_files():
|
||||
|
||||
root = tk.Tk()
|
||||
root.title("Log to CSV Converter")
|
||||
root.geometry("500x120")
|
||||
root.geometry("500x160")
|
||||
|
||||
input_file_var = tk.StringVar()
|
||||
|
||||
@@ -100,9 +114,12 @@ input_frame = tk.Frame(root)
|
||||
input_frame.pack(pady=5, padx=10, fill='x')
|
||||
tk.Label(input_frame, text="Select Input Log File:").pack(side='left')
|
||||
tk.Entry(input_frame, textvariable=input_file_var, width=40).pack(side='left', padx=5)
|
||||
tk.Button(input_frame, text="Browse Input", command=select_input_file).pack(side='left')
|
||||
tk.Button(input_frame, text="Browse Input", bg="#2196F3", command=select_input_file).pack(side='left')
|
||||
|
||||
# Convert button
|
||||
tk.Button(root, text="CONVERT TO CSV", command=process_files, font=("Arial", 14), relief="raised", bg="#4CAF50", fg="white").pack(pady=20, padx=10, fill='x')
|
||||
tk.Button(root, text="CONVERT TO CSV", command=process_files, font=("Arial", 14), relief="raised", bg="#4CAF50", fg="white").pack(pady=10, padx=10, fill='x')
|
||||
|
||||
# Update script button
|
||||
tk.Button(root, text="Update this Application", command=run_update_script, font=("Arial", 12), relief="raised").pack(pady=5, padx=10, fill='x')
|
||||
|
||||
root.mainloop()
|
||||
Reference in New Issue
Block a user