Dictionary instead of list?

This commit is contained in:
Benson Chu 2025-08-23 10:13:49 -05:00
parent 5797c991a0
commit ae7e236072

View file

@ -14,16 +14,20 @@ def do_modify_labels(lib, objs, label, action):
changed = [] changed = []
for obj in objs: for obj in objs:
labels = [] labels = {}
if action != 2: if action != 2:
if "mylabels" in obj: if "mylabels" in obj:
labels = json.loads(obj["mylabels"]) labels = json.loads(obj["mylabels"])
split = label.split(":")
if action == 0: if action == 0:
labels.append(label) if len(split) == 1:
labels = sorted(set(labels)) labels[label] = 0
else:
labels[split[0]] = int(split[1])
elif label in labels: elif label in labels:
labels.remove(label) del labels[label]
obj_mods = { obj_mods = {
"mylabels": json.dumps(labels) "mylabels": json.dumps(labels)