Files
wordsearch/seed.py
T
Mathew Sir Guest the bestandClaude Opus 4.6 9319f08875 feat: expand to 1014 words, add title-case display and 2 new themes
- Move word data from hardcoded seed.py to data/words.json
- Expand from 210 words across 7 categories to 1014 words across 14
  categories (animals, food, colors, sports, space, nature, music,
  science, countries, occupations, ocean, weather, mythology, technology)
- Word list sidebar now shows title case (Tiger) while grid stays
  uppercase; text input remains case-insensitive
- Add Ocean theme (light, blue accents) and Forest theme (dark, amber
  accents on deep green)
- Replace hardcoded rgba values with --coral-bg CSS variable so
  selection highlighting adapts per theme

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-07 02:43:43 -06:00

53 lines
1.3 KiB
Python

"""Seed the database with word categories from data/words.json."""
import json
import os
from db import get_engine, get_session_factory, init_db
from models.category import Category, CategoryWord
DATA_PATH = os.path.join(os.path.dirname(__file__), "data", "words.json")
def load_words():
with open(DATA_PATH) as f:
return json.load(f)
def seed():
engine = get_engine()
init_db(engine)
Session = get_session_factory(engine)
session = Session()
word_data = load_words()
for cat_name, words in word_data.items():
existing = session.query(Category).filter_by(name=cat_name).first()
if existing:
cat = existing
else:
cat = Category(name=cat_name)
session.add(cat)
session.flush()
added = 0
for w in words:
exists = (
session.query(CategoryWord)
.filter_by(category_id=cat.id, word=w)
.first()
)
if not exists:
session.add(CategoryWord(category_id=cat.id, word=w))
added += 1
print(f"Category '{cat_name}': added {added} new words.")
session.commit()
session.close()
print("Done.")
if __name__ == "__main__":
seed()