Spaces:
Sleeping
Sleeping
venkatesh commited on
Commit ·
784e9bd
1
Parent(s): 345193f
added highlight functionality and the B20 + the displaying content of text files by adding a new column called Language
Browse files- __pycache__/helper.cpython-313.pyc +0 -0
- __pycache__/tab1.cpython-313.pyc +0 -0
- __pycache__/tab2.cpython-313.pyc +0 -0
- __pycache__/tab3.cpython-313.pyc +0 -0
- __pycache__/tab4.cpython-313.pyc +0 -0
- __pycache__/tab5.cpython-313.pyc +0 -0
- __pycache__/tab6.cpython-313.pyc +0 -0
- __pycache__/tab7.cpython-313.pyc +0 -0
- helper.py +72 -12
- main.py +0 -0
__pycache__/helper.cpython-313.pyc
ADDED
|
Binary file (56.5 kB). View file
|
|
|
__pycache__/tab1.cpython-313.pyc
ADDED
|
Binary file (8.15 kB). View file
|
|
|
__pycache__/tab2.cpython-313.pyc
ADDED
|
Binary file (7.02 kB). View file
|
|
|
__pycache__/tab3.cpython-313.pyc
ADDED
|
Binary file (9.73 kB). View file
|
|
|
__pycache__/tab4.cpython-313.pyc
ADDED
|
Binary file (7.66 kB). View file
|
|
|
__pycache__/tab5.cpython-313.pyc
ADDED
|
Binary file (14.1 kB). View file
|
|
|
__pycache__/tab6.cpython-313.pyc
ADDED
|
Binary file (9.85 kB). View file
|
|
|
__pycache__/tab7.cpython-313.pyc
ADDED
|
Binary file (9 kB). View file
|
|
|
helper.py
CHANGED
|
@@ -170,33 +170,59 @@ def generate_excel_report(output_folder: Path, marken_index: dict, file_to_facto
|
|
| 170 |
|
| 171 |
nummer_zu_marke = {v: k for k, v in marken_index.items()}
|
| 172 |
data = []
|
| 173 |
-
|
| 174 |
for file in sorted(output_folder.iterdir()):
|
| 175 |
# Process ALL files, not just specific extensions
|
| 176 |
if file.is_file() and is_valid_file(file):
|
| 177 |
name = file.stem
|
| 178 |
# Get file extension for display
|
| 179 |
file_ext = file.suffix.lower() if file.suffix else ''
|
| 180 |
-
|
| 181 |
match = re.match(r"(\d{2})B(\d{2})([a-z0-9]+)", name, re.IGNORECASE)
|
| 182 |
if match:
|
| 183 |
markennummer, blocknummer, marke = match.groups()
|
| 184 |
factor = nummer_zu_marke.get(markennummer, marke)
|
| 185 |
-
|
| 186 |
# Get factorgroup and remove underscores
|
| 187 |
factorgroup = file_to_factorgroup.get(file.name, f"{blocknummer}Unknown")
|
| 188 |
factorgroup = factorgroup.replace('_', '') # Remove all underscores
|
| 189 |
-
|
| 190 |
# Include file extension in the ID column
|
| 191 |
-
|
| 192 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
data.append({
|
| 194 |
"factor": factor,
|
| 195 |
"factorgroup": factorgroup,
|
| 196 |
-
"ID":
|
|
|
|
|
|
|
| 197 |
})
|
| 198 |
|
| 199 |
-
|
|
|
|
| 200 |
|
| 201 |
reordered_data = []
|
| 202 |
for _, row in df_assets.iterrows():
|
|
@@ -210,24 +236,58 @@ def generate_excel_report(output_folder: Path, marken_index: dict, file_to_facto
|
|
| 210 |
# Also remove underscores from the reordered data
|
| 211 |
clean_factor = str(row["factorgroup"]).replace('_', '')
|
| 212 |
clean_factorgroup = str(row["factor"]).replace('_', '')
|
| 213 |
-
|
| 214 |
reordered_data.append({
|
| 215 |
"Group": group,
|
| 216 |
"factor": clean_factor,
|
| 217 |
"factorgroup": clean_factorgroup,
|
| 218 |
-
"ID": row["ID"]
|
|
|
|
| 219 |
})
|
| 220 |
|
| 221 |
-
df_reordered = pd.DataFrame(reordered_data, columns=["Group", "factor", "factorgroup", "ID"])
|
| 222 |
df_reordered = df_reordered.sort_values(by='Group', ascending=True).reset_index(drop=True)
|
| 223 |
-
|
| 224 |
with pd.ExcelWriter(final_excel_path, engine='openpyxl') as writer:
|
| 225 |
df_assets.to_excel(writer, index=False, sheet_name="Assets")
|
| 226 |
df_reordered.to_excel(writer, index=False, sheet_name="Reordered")
|
| 227 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
return final_excel_path
|
| 229 |
|
| 230 |
|
|
|
|
| 231 |
def add_brand_pages_with_png_extensions(elements, marken_spalten, renamed_files_by_folder_and_marke, marken_index):
|
| 232 |
"""Add brand overview pages with .png extensions in labels"""
|
| 233 |
styles = getSampleStyleSheet()
|
|
|
|
| 170 |
|
| 171 |
nummer_zu_marke = {v: k for k, v in marken_index.items()}
|
| 172 |
data = []
|
| 173 |
+
|
| 174 |
for file in sorted(output_folder.iterdir()):
|
| 175 |
# Process ALL files, not just specific extensions
|
| 176 |
if file.is_file() and is_valid_file(file):
|
| 177 |
name = file.stem
|
| 178 |
# Get file extension for display
|
| 179 |
file_ext = file.suffix.lower() if file.suffix else ''
|
| 180 |
+
|
| 181 |
match = re.match(r"(\d{2})B(\d{2})([a-z0-9]+)", name, re.IGNORECASE)
|
| 182 |
if match:
|
| 183 |
markennummer, blocknummer, marke = match.groups()
|
| 184 |
factor = nummer_zu_marke.get(markennummer, marke)
|
| 185 |
+
|
| 186 |
# Get factorgroup and remove underscores
|
| 187 |
factorgroup = file_to_factorgroup.get(file.name, f"{blocknummer}Unknown")
|
| 188 |
factorgroup = factorgroup.replace('_', '') # Remove all underscores
|
| 189 |
+
|
| 190 |
# Include file extension in the ID column
|
| 191 |
+
only_id = name
|
| 192 |
+
is_text_file = False
|
| 193 |
+
is_b20_id = False
|
| 194 |
+
|
| 195 |
+
# Check if ID contains "B20" substring
|
| 196 |
+
if "B20" in only_id.upper():
|
| 197 |
+
is_b20_id = True
|
| 198 |
+
# Rule 3: If ID contains B20, always use .png
|
| 199 |
+
language_value = only_id + ".png"
|
| 200 |
+
elif file_ext == '.txt':
|
| 201 |
+
# Rule 2: Read text file content
|
| 202 |
+
is_text_file = True
|
| 203 |
+
try:
|
| 204 |
+
# Read the content of the .txt file
|
| 205 |
+
with open(file, 'r', encoding='utf-8', errors='ignore') as txt_file:
|
| 206 |
+
txt_content = txt_file.read().strip()
|
| 207 |
+
# Use the content instead of filename
|
| 208 |
+
language_value = txt_content if txt_content else "[Empty file]"
|
| 209 |
+
except Exception as e:
|
| 210 |
+
# If error reading file, show error message
|
| 211 |
+
language_value = f"[Error reading file: {str(e)}]"
|
| 212 |
+
else:
|
| 213 |
+
# Rule 1: For normal files, show ID + extension
|
| 214 |
+
language_value = name + file_ext
|
| 215 |
+
|
| 216 |
data.append({
|
| 217 |
"factor": factor,
|
| 218 |
"factorgroup": factorgroup,
|
| 219 |
+
"ID": only_id,
|
| 220 |
+
"Language": language_value,
|
| 221 |
+
"highlight_yellow": is_text_file or is_b20_id # Track which cells need highlighting
|
| 222 |
})
|
| 223 |
|
| 224 |
+
|
| 225 |
+
df_assets = pd.DataFrame(data, columns=["factor", "factorgroup", "ID", "Language"])
|
| 226 |
|
| 227 |
reordered_data = []
|
| 228 |
for _, row in df_assets.iterrows():
|
|
|
|
| 236 |
# Also remove underscores from the reordered data
|
| 237 |
clean_factor = str(row["factorgroup"]).replace('_', '')
|
| 238 |
clean_factorgroup = str(row["factor"]).replace('_', '')
|
| 239 |
+
|
| 240 |
reordered_data.append({
|
| 241 |
"Group": group,
|
| 242 |
"factor": clean_factor,
|
| 243 |
"factorgroup": clean_factorgroup,
|
| 244 |
+
"ID": row["ID"],
|
| 245 |
+
"Language": row["Language"]
|
| 246 |
})
|
| 247 |
|
| 248 |
+
df_reordered = pd.DataFrame(reordered_data, columns=["Group", "factor", "factorgroup", "ID", "Language"])
|
| 249 |
df_reordered = df_reordered.sort_values(by='Group', ascending=True).reset_index(drop=True)
|
| 250 |
+
|
| 251 |
with pd.ExcelWriter(final_excel_path, engine='openpyxl') as writer:
|
| 252 |
df_assets.to_excel(writer, index=False, sheet_name="Assets")
|
| 253 |
df_reordered.to_excel(writer, index=False, sheet_name="Reordered")
|
| 254 |
|
| 255 |
+
# Apply yellow highlighting to Language column cells
|
| 256 |
+
workbook = writer.book
|
| 257 |
+
from openpyxl.styles import PatternFill
|
| 258 |
+
|
| 259 |
+
yellow_fill = PatternFill(start_color='FFFF00', end_color='FFFF00', fill_type='solid')
|
| 260 |
+
|
| 261 |
+
# Highlight in Assets sheet
|
| 262 |
+
assets_sheet = workbook['Assets']
|
| 263 |
+
language_col_idx = 4 # Language is the 4th column (D)
|
| 264 |
+
for row_idx in range(2, len(df_assets) + 2): # Start from row 2 (after header)
|
| 265 |
+
cell = assets_sheet.cell(row=row_idx, column=language_col_idx)
|
| 266 |
+
# Check if this row should be highlighted based on the highlight_yellow flag
|
| 267 |
+
if row_idx - 2 < len(data):
|
| 268 |
+
if data[row_idx - 2].get("highlight_yellow", False):
|
| 269 |
+
cell.fill = yellow_fill
|
| 270 |
+
|
| 271 |
+
# Highlight in Reordered sheet
|
| 272 |
+
reordered_sheet = workbook['Reordered']
|
| 273 |
+
language_col_idx = 5 # Language is the 5th column (E)
|
| 274 |
+
id_col_idx = 4 # ID is the 4th column (D)
|
| 275 |
+
|
| 276 |
+
# Create a mapping of ID to highlight_yellow flag for quick lookup
|
| 277 |
+
id_to_highlight = {item["ID"]: item.get("highlight_yellow", False) for item in data}
|
| 278 |
+
|
| 279 |
+
for row_idx in range(2, len(df_reordered) + 2): # Start from row 2 (after header)
|
| 280 |
+
cell = reordered_sheet.cell(row=row_idx, column=language_col_idx)
|
| 281 |
+
# Read the ID from this row to check if it should be highlighted
|
| 282 |
+
id_cell = reordered_sheet.cell(row=row_idx, column=id_col_idx)
|
| 283 |
+
id_value = id_cell.value
|
| 284 |
+
if id_value and id_to_highlight.get(id_value, False):
|
| 285 |
+
cell.fill = yellow_fill
|
| 286 |
+
|
| 287 |
return final_excel_path
|
| 288 |
|
| 289 |
|
| 290 |
+
|
| 291 |
def add_brand_pages_with_png_extensions(elements, marken_spalten, renamed_files_by_folder_and_marke, marken_index):
|
| 292 |
"""Add brand overview pages with .png extensions in labels"""
|
| 293 |
styles = getSampleStyleSheet()
|
main.py
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|