- Increment catalog version from 3 to 4 - Add 330+ grain/cereal items including gluten-free variants, pasta types, rice varieties, flour, and breakfast cereals with French/English names - Add 200+ condiment items covering sauces, spices, oils, vinegars, and seasonings - Add 150+ beverage items including juices, sodas, coffee, tea, and alcoholic drinks
87 lines
2.3 KiB
Python
87 lines
2.3 KiB
Python
import json, re
|
|
|
|
with open('items_data.json', 'r', encoding='utf-8') as f:
|
|
items_data = json.load(f)
|
|
|
|
path = 'app/src/main/java/com/safebite/app/domain/engine/CatalogProvider.kt'
|
|
with open(path, 'r', encoding='utf-8') as f:
|
|
lines = f.readlines()
|
|
|
|
# Find the buildList closing brace — it's the first standalone ' }' after the last add(CatalogItem in the items block
|
|
buildlist_end_idx = None
|
|
last_add_idx = None
|
|
for i, line in enumerate(lines):
|
|
if 'add(CatalogItem(' in line:
|
|
last_add_idx = i
|
|
|
|
if last_add_idx is None:
|
|
print("No add(CatalogItem found")
|
|
exit(1)
|
|
|
|
# Search forward from last_add_idx for the closing brace of buildList
|
|
for i in range(last_add_idx + 1, len(lines)):
|
|
if lines[i].strip() == '}':
|
|
buildlist_end_idx = i
|
|
break
|
|
|
|
if buildlist_end_idx is None:
|
|
print("Could not find buildList end")
|
|
exit(1)
|
|
|
|
print(f"buildList ends at line {buildlist_end_idx + 1}")
|
|
|
|
# Collect existing names in the buildList
|
|
existing_names = set()
|
|
for line in lines[:buildlist_end_idx]:
|
|
m = re.search(r'CatalogItem\("([^"]+)"', line)
|
|
if m:
|
|
existing_names.add(m.group(1))
|
|
|
|
cat_map = {
|
|
'spices': 'Condiments & Épices',
|
|
'frozen': 'Épicerie',
|
|
'pantry': 'Épicerie',
|
|
'snacks': 'Snacks & Bonbons',
|
|
'beverages': 'Boissons',
|
|
'cleaning': 'Maison',
|
|
'hygiene': 'Santé',
|
|
'pets': 'Animaux',
|
|
'garden': 'Jardin',
|
|
'misc': 'Épicerie',
|
|
}
|
|
|
|
emoji_map = {
|
|
'Condiments & Épices': '🧂',
|
|
'Épicerie': '🌾',
|
|
'Snacks & Bonbons': '🍿',
|
|
'Boissons': '🥤',
|
|
'Maison': '🏠',
|
|
'Santé': '💊',
|
|
'Animaux': '🐾',
|
|
'Jardin': '🌱',
|
|
}
|
|
|
|
additions = []
|
|
for src_cat, items in items_data.items():
|
|
target_cat = cat_map[src_cat]
|
|
emoji = emoji_map[target_cat]
|
|
for name in items:
|
|
if name in existing_names:
|
|
continue
|
|
existing_names.add(name)
|
|
safe_name = name.replace('"', '\\"')
|
|
additions.append(f' add(CatalogItem("{safe_name}", "{target_cat}", "{emoji}"))\n')
|
|
|
|
if additions:
|
|
# Insert before buildlist_end_idx, with blank line before
|
|
insert_text = '\n'.join(additions) + '\n'
|
|
lines.insert(buildlist_end_idx, insert_text)
|
|
print(f"Inserted {len(additions)} items before buildList end")
|
|
else:
|
|
print("No new items")
|
|
|
|
with open(path, 'w', encoding='utf-8') as f:
|
|
f.writelines(lines)
|
|
|
|
print("Done")
|