Importa articles de El Paà­s a Zotero

Aquest és el meu primer “traductor” per a Zotero. Aquest traductor és per a importar articles de El Paí­s.

REPLACE INTO translators VALUES ('2ddd2254-de8e-4b4a-924d-ce08718cfb0a', '1.0.0b3r1', '', '2007-06-12 19:58:11', '0', '100', '4', 'El Pais - Spanish newspaper', 'Joan Junyent Tarrida', '^http://www\.elpais\.com', 
'function detectWeb(doc, url) {
	var Re = new RegExp("articulo");
	if(Re.test(doc.location.href)) {
		return "newspaperArticle";
	} else { return false; }
}
', 
'function scrape(doc, url) {
	var namespace = doc.documentElement.namespaceURI;
	var nsResolver = namespace ? function(prefix) {
		if (prefix == ''x'') return namespace; else return null;
	} : null;

       var newItem = new Zotero.Item("newspaperArticle");
       newItem.publicationTitle = "El Paí­s";
       newItem.edition = "elpais.com";
       newItem.language = "Castellano";
       newItem.rights = "Copyright Diario EL PAÍS, S.L.";
       newItem.url = doc.location.href;
       newItem.repository = "Elpais.com";
       newItem.attachments.push({url:doc.location.href, title:doc.title, mimeType:"text/html"});

// Autor
       var xpathautor =''//div[@class="firma"]/p/strong'';
       var autor = doc.evaluate(xpathautor, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;

		var authors = autor.split(" / ");
		for each(var author in authors) {
			// fix capitalization
			var words = author.split(" ");
			for(var i in words) {
				words[i] = words[i][0].toUpperCase()+words[i].substr(1).toLowerCase();
			}
			author = words.join(" ");
			
			if(words[0] == "El") {
				newItem.creators.push({lastName:author, creatorType:"author", fieldMode:true});
			} else {
				newItem.creators.push(Zotero.Utilities.cleanAuthor(author, "author"));
			}
		}


// Titulo
      var xpath = ''//h1'';
      newItem.title = Zotero.Utilities.cleanString(doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent);
// Fecha
       var xpathfecha =''//div[@class="firma"]/p/text()[2]'';
       newItem.date = Zotero.Utilities.cleanString(doc.evaluate(xpathfecha, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent);
// Resumen
       var xpathresumen =''//div[@class="estructura_2col_1zq"]/div[@class="margen_n"]/p[1]'';
       newItem.abstract = Zotero.Utilities.cleanString(doc.evaluate(xpathresumen, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent);
// Seccion
       var xpathsection=''//ul/li[@class="on"]/a[1]'';
       newItem.section = Zotero.Utilities.cleanString(doc.evaluate(xpathsection, doc, nsResolver,XPathResult.ANY_TYPE, null).iterateNext().textContent);
// Extra
       var xpathextra = ''//div[@class="firma"]/p'';
       newItem.extra = Zotero.Utilities.cleanString(doc.evaluate(xpathextra,doc, nsResolver, XPathResult.ANY_TYPE,null).iterateNext().textContent);

       newItem.complete();

}

function doWeb(doc, url) {
               scrape(doc);
}
');

Per instal·lar-lo només cal obrir la base de dades (la trobarí s dins de la carpeta zotero dins del perfil del Firefox) amb un client sqlite (per exemple el SQLite Database Browser) i executar el codi anterior en una consulta. Per algun motiu que per ara desconec el camp “abstract” no s’importa.