|
# The script below will update ALL your tags except those in the skip_tags list. Use it with caution. |
|
# It also splits all tags that have more than a word. It saves both the old tag and the new one. |
|
# That is, you have ("my tag word"), and you get ("my","tag", "word", "my tag word"). |
|
#The API_KEY and LIBRARY_ID are private. See the documentation.api_key = "xxxxx" |
|
# Documentation: https://pyzotero.readthedocs.io/en/latest/ |
|
# Original thread: https://forums.zotero.org/discussion/92493/any-way-to-switch-all-tags-to-all-lower-case-or-ignore-case-in-tags |
|
|
|
library_id = 0000000 |
|
library_type = "user" |
|
from pyzotero import zotero |
|
zot = zotero.Zotero(library_id, library_type, api_key) |
|
|
|
|
|
|
|
skip_tags = [ |
|
"⛔ No doifound", |
|
"⛔ No DOI found", |
|
"#broken_attachments", |
|
"#duplicate_attachments", |
|
"#nosource", |
|
"❓ multiple doi" |
|
] |
|
collections_keys = [x for x in zot.collections()] |
|
for coll in zot.collections(): |
|
# if coll["data"]["name"] != "TEST_COLLECTION": |
|
# continue |
|
print("UPDATING: collection: " + coll["data"]["name"] ) |
|
print(coll["key"]) |
|
print(zot.num_collectionitems(coll["key"])) |
|
items = zot.collection_items(coll["key"]) |
|
update_items = [] |
|
for item in items: |
|
old_tags = item["data"]["tags"].copy() |
|
for tag in item["data"]["tags"]: |
|
if tag["tag"] in skip_tags: # skip tags |
|
continue |
|
if tag["tag"].startswith("zotero"): # it belongs to BetterNotes |
|
continue |
|
tag["tag"] = tag["tag"].lower() |
|
multiple_tags = tag["tag"].split(" ") |
|
if len(multiple_tags) > 1: |
|
for new_tag in multiple_tags: |
|
item["data"]["tags"].append({"tag":new_tag}) |
|
new_tags = item["data"]["tags"] |
|
if old_tags != new_tags: |
|
changed_tags = [x["tag"].lower() for x in item["data"]["tags"]] |
|
print(changed_tags) |
|
zot.update_item(item) |
|
# for item in items: |
|
# # print(item["data"]["title"]) |
|
# print(item["data"]["tags"]) |
|
|
|
print("DONE") |