Skip to content

Instantly share code, notes, and snippets.

@rmzelle
Created April 19, 2009 12:35
Show Gist options
  • Save rmzelle/98053 to your computer and use it in GitHub Desktop.
Save rmzelle/98053 to your computer and use it in GitHub Desktop.
function lookupPMIDs(ids, doc) {
Zotero.wait();
var newUri = "http://books.google.com/books/feeds/volumes/"+ids;
Zotero.debug(newUri);
Zotero.Utilities.HTTP.doGet(newUri, function(text) {
// Remove xml parse instruction and doctype
text = text.replace(/<!DOCTYPE[^>]*>/, "").replace(/<\?xml[^>]*\?>/, "");
var xml = new XML(text);
//Zotero.debug(xml);
default xml namespace = "http://www.w3.org/2005/Atom";
Zotero.debug(xml.id);
default xml namespace = "http://purl.org/dc/terms";
Zotero.debug(xml.date.text().toString());
var newItem = new Zotero.Item("book");
newItem.url = doc.location.href;
var title = new Array(xml.title);
newItem.title = xml.title[0].text().toString();
newItem.date = xml.date.text().toString();
var pages = xml.format.text().toString();
var pagesRe = new RegExp(/(\d+)( pages)/);
var pagesMatch = pagesRe.exec(pages);
if (pagesMatch[1]) {
newItem.pages = pagesMatch[1];
} else {
newItem.pages = pages;
}
/*
var ISBN;
var identifiers = new Array(xml.identifier);
var identifiersRe = new RegExp(/(ISBN:)(\w+)/);
for (var i in identifiers ) {
var identifierMatch = identifiersRe.exec(identifiers[i]);
if (identifierMatch[1] && !ISBN) {
Zotero.debug(identifierMatch[2]);
ISBN = (identifierMatch[2]);
} else if (ISBN) {
ISBN = ISBN+', '+identifierMatch[2];
}
}
newItem.ISBN = ISBN;
*/
var authors = new Array(xml.creator);
Zotero.debug(authors);//RZ: this debug shows that the array has only a length of one
for (var i in authors) {
newItem.creators.push(Zotero.Utilities.cleanAuthor(authors[i].text().toString(), "author"));
}
//RZ: deleting the three lines below gives an error
if(0) {
newItem.DOI = xml.PubmedArticle[i].PubmedData.ArticleIdList.ArticleId.(@IdType == "doi" ).text().toString();
}
newItem.complete();
Zotero.done();
});
}
function doWeb(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
var ids = new Array();
ids.push("TFXua_jm8T0C");
Zotero.debug(ids);
lookupPMIDs(ids, doc);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment