Skip to content

Instantly share code, notes, and snippets.

@zuphilip
Last active December 26, 2019 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zuphilip/66699b4515e4d0094f7333240948b108 to your computer and use it in GitHub Desktop.
Save zuphilip/66699b4515e4d0094f7333240948b108 to your computer and use it in GitHub Desktop.
Zotero author lookup in lobid API and enhance with GND ids
// WHAT: for each selected item, go through all creators and look each of them up in lobid GND API
// if any differentiated persons are found, then update this information about possible
// GND machtes in the extra field (proof-of-concept)
// HOW: can be run within Zotero "Run Javascript" tool
var items = Zotero.getActiveZoteroPane().getSelectedItems();
var apiCall = "https://lobid.org/gnd/search?q=";
var suffix = "&filter=type:DifferentiatedPerson&format=json";
for (let item of items) {
var creators = item.getCreators();
for (let creator of creators) {
let query = [creator.firstName, creator.lastName].join(" ").replace(/ /g, "+");
await Zotero.HTTP.doGet(apiCall + query + suffix, function (obj) {
data = JSON.parse(obj.responseText);
if (data.totalItems > 0) {
let ids = data.member.map(x => x.id).join(", ");
let extra = item.getField("extra");
item.setField("extra", extra + "\n" + creator.lastName + " = " + ids + " ?");
note += ids;
}
});
}
}
return items;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment