icon and units
This commit is contained in:
21
main.py
21
main.py
@@ -18,9 +18,11 @@ def parse_logs(log_text):
|
||||
i += 1
|
||||
continue
|
||||
|
||||
match = re.match(r'^GROSS\s+(\d+)\s*lb$', line)
|
||||
# Updated regex to capture any units (lb, kg, g, etc.)
|
||||
match = re.match(r'^GROSS\s+(\d+)\s*([a-zA-Z]+)$', line)
|
||||
if match:
|
||||
weight = int(match.group(1))
|
||||
units = match.group(2)
|
||||
i += 2 # Skip to timestamp line
|
||||
if i < len(lines):
|
||||
ts_line = lines[i].strip()
|
||||
@@ -29,7 +31,7 @@ def parse_logs(log_text):
|
||||
try:
|
||||
dt = datetime.strptime(ts_line, '%I:%M %p %m/%d/%y')
|
||||
excel_ts = dt.strftime('%m/%d/%Y %I:%M %p')
|
||||
pairs.append((weight, excel_ts))
|
||||
pairs.append((weight, units, excel_ts))
|
||||
except ValueError:
|
||||
i += 1
|
||||
continue
|
||||
@@ -44,20 +46,21 @@ def parse_logs(log_text):
|
||||
def write_csv1(pairs, filename):
|
||||
with open(filename, 'w', newline='') as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerow(['WEIGHT', 'TIMESTAMP'])
|
||||
for weight, timestamp in pairs:
|
||||
writer.writerow([weight, timestamp])
|
||||
writer.writerow(['WEIGHT', 'UNITS', 'TIMESTAMP'])
|
||||
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_TIME', 'TARE_WEIGHT', 'TARE_TIME', 'NET'])
|
||||
writer.writerow(['GROSS_WEIGHT', 'GROSS_UNITS', 'GROSS_TIME', 'TARE_WEIGHT', 'TARE_UNITS', 'TARE_TIME', 'NET', 'NET_UNITS'])
|
||||
for j in range(0, len(pairs), 2):
|
||||
if j + 1 < len(pairs):
|
||||
gross_weight, gross_time = pairs[j]
|
||||
tare_weight, tare_time = pairs[j + 1]
|
||||
gross_weight, gross_units, gross_time = pairs[j]
|
||||
tare_weight, tare_units, tare_time = pairs[j + 1]
|
||||
net = gross_weight - tare_weight
|
||||
writer.writerow([gross_weight, gross_time, tare_weight, tare_time, net])
|
||||
# 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])
|
||||
|
||||
def select_input_file():
|
||||
filename = filedialog.askopenfilename(filetypes=[("Text files", "*.txt"), ("All files", "*.*")])
|
||||
|
||||
Reference in New Issue
Block a user