Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
787 B
2
Indexable
Never
subcategories = ["Hiefs", "sdfgs"] # считать из эксельки
title_to_id = {}
for s in subcategories:
    subcategoryies_db = list(db.categories.find({"title.en": s}))
    if not subcategoryies_db:
        print("NOT FOUND SUBCATEGORY: " + s)
        raise Exception("not found subcategory")
    subcat_result = None
    for ss in subcategoryies_db:
        parent = db.categories.find_one({"_id": ss["parent_id"]})
        if str(parent["location_id"]) == "asdgfaskdlgjl":
            subcat_result = ss["_id"]
    if not subcat_result:
        print("NOT FOUND parent category for: " + s)
        raise Exception("not found parent category")
    title_to_id[s] = subcat_result


for p in products:
    db.products.insert({"subcategories": [title_to_id[p["subcategory"]]]})