Help needed: How to rename mass of tags?
Hi,
I have currently the problem, that I have to rename all my structured tags in my library (and my company intern group libraries) according a new company wide style. Doing this by hand in the tag-window is possible but would be an enormous work.
An example: I have tags with the following layout A:project>nr>E20145 and the final layout should be >project>nr>E20145. I have to search-replace all "A:" by ">" in all tags.
Is there an easy way doing this directly and more efficently as renaming it by hand?
What is the best way herefore?
Thanks for any help or suggestions.
SIGGI.
I have currently the problem, that I have to rename all my structured tags in my library (and my company intern group libraries) according a new company wide style. Doing this by hand in the tag-window is possible but would be an enormous work.
An example: I have tags with the following layout A:project>nr>E20145 and the final layout should be >project>nr>E20145. I have to search-replace all "A:" by ">" in all tags.
Is there an easy way doing this directly and more efficently as renaming it by hand?
What is the best way herefore?
Thanks for any help or suggestions.
SIGGI.
(But some of the group work with zotero4 as firefox plugin)
https://www.zotero.org/support/dev/client_coding/javascript_api#batch_editing
On Zotero 5, easiest would likely be to go through the server API using Pyzotero
https://www.zotero.org/support/dev/client_coding/javascript_api
I'm using zotero5, therefore I should try pyzotero.
Do the zotero javascript method don't work for zotero5 anymore?
I'm not really familiar with python / javascript and the zotero API. Do you know a step-by-step example, I can follow (perhaps for the pyzotero way)?
I will try to work with pyzotero. Any help for this way is welcome ;-).
But I can't find an API method to modify a tag.
Is there any simple way to modify the contents of a tag with a regexp command?
It is a bit complicated for a non-python man as me. But I will try it.
Perhaps it would be an simple zotero API extension to have a method to modify a tag. I think it would be very similar to the delete_tag method.
Now I have written a python script, which adds renamend tags and finally deletes the old one. It works so far.
In the group library at the Zotero-Server the "deleted" tags seemed to be deleted.
But in my "local" group lib, the "deleted" tags are still there. Also after sync. Also after cleaning the trash. Also after restarting zotero5.
What is going wrong?
I have tried to replace all tags with "A:..." by ">".
In my local EL-Gruppe Lib I have an item with both tags e.g. A:proj>R>TUS-BurstWave-Analyse and the new replacement >proj>R>TUS-BrustWave-Analyse. The tag-selector shows both tags.
That means, that the pyzotero method "zotero.delete_tags" do not work properly?
Do I understand you right, you advice me to manually delete the "undeleted" tags in the tag-selector?
Also, what underlying API requests are you using? Generally the way to change a tag via the API would be to make item writes that simply swap one tag for another.
For tag-renaming I use pyzotero and the following python-skript. Initially I didn't used the zotero.everything method - so I got perhaps only 50 search results and not all (perhaps was that a problem).
Here the script I use now:
#------------
from pyzotero import zotero
zot = zotero.Zotero(libnummer, libtype,libapikey )
worte = zot.everything(zot.tags(q="A:")) ##############EDIT
#
for wort in worte:
wortneu = wort.replace("A:", ">") ########## EDIT
print('Ersetze: %s -> %s' % (wort, wortneu))
# items mit dem zu ersetzenden Tag finden
items = zot.everything(zot.items(tag=wort))
# In allen gefundenen Items den den neuen Tag hinzufügen
# Alter Tag wird NICHT hier gelöscht (er muss global gelöscht werden)
for item in items:
print('Item Type: %s | Key: %s' % (item['data']['itemType'], item['data']['key']))
# Neuer Tag zum aktuellem Item hinzufügen
zot.add_tags(item,wortneu)
#
# Alle alten Tags (A:) aus Lib löschen
for wort in worte:
print('Lösche: %s' % wort)
updated = zot.delete_tags(wort)
#-------------------------------------
But after manual sync, it seems to be the same situation as before: locally I have some item with A:-Tags (also in the tag-selector) and online all A:-Tags are removed.
e.g. the item: "Zotero - Home": locally with A:prod>Zotero,... online without A:-Tag and without >prod>Zotero
When I change tags (add/delete them) over pyzotero (zotero API) it takes some time (about 1min) until I see the changes in the web-version of the group lib. I have to refresh the tag-selector (web-version) by hand. Reloading the web-page is not sufficient. For some time the tags are deleted in the tag-selector but still visible at the items. After additional time the tags are also deleted at the items (in the web version).
But nothing happens in my local group library! I sync manually from time to time (10min afterwards, 30min afterwards, 1day afterwards) but nothing happens. The deleted tags stay visible in the tag selector and at the items.
Is it possible, that the local version do not really see, that there are changes made at the server, because I have done them with pyzotero/zotero API?
you asked where the libnumber, libtype and libapikey you need for pyzotero come from.
For libtype there exist only 2 possiblities "user" or "group" - whether which kind of library you will treat. MyLib is of type "user".
lipapikey you can generate in your account at zotero.org (settings/feeds-api)
The libnumber you also find under settings/feeds-api. It's your userID. Thats the libnumber for your "user" type lib. The libnumbers for the groups you can find, if you click in zotero.org in your account on the corresponding group-library. The number displayed in the url is the libnumber for this group to use for pyzotero.
That's the way I have found the stuff. Perhaps there exist a more easier way to do it?