Files
GoogleSheetBot/processing.py

112 lines
3.1 KiB
Python

import re
def normalize(text):
if not text:
return ""
return re.sub(r"\s+", "", text)
def get_finish_suffix(color):
"""Extracts the finish suffix (e.g., 'G', 'S', 'M') from a color string."""
if not color:
return None
return color.strip().split('-')[-1].upper()
def get_finish_type(row_data):
"""Determines the finish type (GLOSS, SATIN, MAT, MIX) based on color suffixes."""
try:
top_suffix = get_finish_suffix(row_data.get("color_top"))
body_suffix = get_finish_suffix(row_data.get("color_body"))
if not top_suffix and not body_suffix:
return None
# If one suffix is missing, assume it's the same as the other.
top_suffix = top_suffix or body_suffix
body_suffix = body_suffix or top_suffix
suffix_to_category = {
'G': 'gloss',
'S': 'satin',
'M': 'mat',
'R': 'mat',
'MAT': 'mat',
'RAW': 'mat',
}
top_category = suffix_to_category.get(top_suffix)
body_category = suffix_to_category.get(body_suffix)
if not top_category or not body_category:
return None # Suffix not in our map
if top_category == body_category:
return top_category.upper()
if 'mat' in {top_category, body_category}:
return 'MIX'
except (KeyError, AttributeError):
# This will catch if row_data is not a dict or keys are missing
return None
return None
def process_row(row, mayo, counter):
"""Processes a single row from the sheet."""
if len(row) < 3:
return None # Skip rows with insufficient columns
link = row[1]
nr_zam = row[2]
if not link:
return None
print(f"\n🔗 Sprawdzam: {link}")
try:
info = mayo.get_order_info(link)
order_number = info["order_number"]
model = info["model"]
print(f"Nr z arkusza: {nr_zam}")
print(f"Nr ze strony: {order_number}")
print(f"Model: {model}")
if normalize(order_number) == normalize(nr_zam):
print("✅ Numer się zgadza")
else:
print("⚠️ Numer NIE pasuje!")
row_data = [
counter,
link,
nr_zam,
model,
get_finish_type(info),
info.get("color_top"),
info.get("color_body"),
info.get("color_neck"),
info.get("color_head"),
info.get("finish_kc"),
info.get("finish_s"),
]
print(f"raw_data: {row_data}")
return row_data
except Exception as e:
print(f"❌ Błąd podczas przetwarzania linku {link}: {e}")
return None
def process_all_rows(rows, mayo):
"""Processes all rows from the sheet."""
rows_to_process = []
counter = 1
# Skip header row by starting from index 1
for row in rows[1:]:
processed_row = process_row(row, mayo, counter)
if processed_row:
rows_to_process.append(processed_row)
counter += 1
return rows_to_process