A simple import translator for SciDataCon papers into Zotero. Simply place into your Zotero data directory https://www.zotero.org/support/zotero_data and restart Zotero & your browser
{ | |
"translatorID": "37d89f07-a5cd-42e5-a929-6f02af2c4a18", | |
"label": "SciDataCon2016", | |
"creator": "Sebastian Karcher", | |
"target": "^https?://www\\.scidatacon\\.org/2016/sessions/\\d+/paper/\\d+", | |
"minVersion": "3.0", | |
"maxVersion": "", | |
"priority": 100, | |
"inRepository": true, | |
"translatorType": 4, | |
"browserSupport": "gcsibv", | |
"lastUpdated": "2016-09-12 15:45:48" | |
} | |
/* | |
***** BEGIN LICENSE BLOCK ***** | |
Copyright © 2016 Sebastian Karcher | |
This file is part of Zotero. | |
Zotero is free software: you can redistribute it and/or modify | |
it under the terms of the GNU Affero General Public License as published by | |
the Free Software Foundation, either version 3 of the License, or | |
(at your option) any later version. | |
Zotero is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU Affero General Public License for more details. | |
You should have received a copy of the GNU Affero General Public License | |
along with Zotero. If not, see <http://www.gnu.org/licenses/>. | |
***** END LICENSE BLOCK ***** | |
*/ | |
function detectWeb(doc, url) { | |
return "presentation"; | |
/*else if (getSearchResults(doc, true)) { | |
return "multiple"; | |
} */ | |
} | |
function getSearchResults(doc, checkOnly) { | |
//not currently using | |
var items = {}; | |
var found = false; | |
//TODO: adjust the xpath | |
var rows = ZU.xpath(doc, '//a[contains(@href, "/article/")]'); | |
for (var i=0; i<rows.length; i++) { | |
//TODO: check and maybe adjust | |
var href = rows[i].href; | |
//TODO: check and maybe adjust | |
var title = ZU.trimInternal(rows[i].textContent); | |
if (!href || !title) continue; | |
if (checkOnly) return true; | |
found = true; | |
items[href] = title; | |
} | |
return found ? items : false; | |
} | |
function doWeb(doc, url) { | |
if (detectWeb(doc, url) == "multiple") { | |
Zotero.selectItems(getSearchResults(doc, false), function (items) { | |
if (!items) { | |
return true; | |
} | |
var articles = []; | |
for (var i in items) { | |
articles.push(i); | |
} | |
ZU.processDocuments(articles, scrape); | |
}); | |
} else { | |
scrape(doc, url); | |
} | |
} | |
function scrape (doc, url) { | |
var item = new Zotero.Item("presentation"); | |
item.title = ZU.xpathText(doc, '//div[@class="container"]//h1'); | |
item.meetingName = "SciDataCon2016"; | |
item.place = "Denver"; | |
item.date = "2016-09-12" | |
var author = ZU.xpathText(doc, '//div[@class="container"]//h3[contains(text(), "Authors")]'); | |
if (author) { | |
var authors = author.replace(/^Authors:\s*/, "").split(/\s*,\s*/); | |
for (var i = 0; i<authors.length; i++) { | |
item.creators.push(ZU.cleanAuthor(authors[i], "author")); | |
} | |
} | |
item.attachments.push({document:doc, title: "SciDataCon Full Text Snapshot"}) | |
item.complete(); | |
} | |
/** BEGIN TEST CASES **/ | |
var testCases = [ | |
{ | |
"type": "web", | |
"url": "http://www.scidatacon.org/2016/sessions/40/paper/343/", | |
"items": [ | |
{ | |
"itemType": "presentation", | |
"title": "Next Steps Towards Making Data Count: Exposing usage metrics for data objects", | |
"creators": [ | |
{ | |
"firstName": "Amber", | |
"lastName": "Budden", | |
"creatorType": "author" | |
}, | |
{ | |
"firstName": "Stephen", | |
"lastName": "Abrams", | |
"creatorType": "author" | |
}, | |
{ | |
"firstName": "John", | |
"lastName": "Chodacki", | |
"creatorType": "author" | |
}, | |
{ | |
"firstName": "Patricia", | |
"lastName": "Cruse", | |
"creatorType": "author" | |
}, | |
{ | |
"firstName": "Martin", | |
"lastName": "Fenner", | |
"creatorType": "author" | |
}, | |
{ | |
"firstName": "Matthew B.", | |
"lastName": "Jones", | |
"creatorType": "author" | |
}, | |
{ | |
"firstName": "John", | |
"lastName": "Kratz", | |
"creatorType": "author" | |
}, | |
{ | |
"firstName": "Laura Garcia", | |
"lastName": "Rueda", | |
"creatorType": "author" | |
}, | |
{ | |
"firstName": "Dave", | |
"lastName": "Vieglais", | |
"creatorType": "author" | |
} | |
], | |
"date": "2016-09-12", | |
"meetingName": "SciDataCon2016", | |
"place": "Denver", | |
"shortTitle": "Next Steps Towards Making Data Count", | |
"attachments": [ | |
{ | |
"title": "SciDataCon Full Text Snapshot" | |
} | |
], | |
"tags": [], | |
"notes": [], | |
"seeAlso": [] | |
} | |
] | |
} | |
] | |
/** END TEST CASES **/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment