Skip to content

Commit 248ddc2

Browse files
committed
add HAPI (Beta) translator. This is a public beta, but we'll need to switch the URL as this becomes more broadly available
1 parent f733aef commit 248ddc2

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
{
2+
"translatorID": "cc4b1ea4-3349-4bb4-af55-cce5e06e4669",
3+
"label": "Hispanic-American Periodical Index (Beta)",
4+
"creator": "Sebastian Karcher",
5+
"target": "https?://newstaging\\.hapi\\.imagistic\\.com/",
6+
"minVersion": "3.0",
7+
"maxVersion": "",
8+
"priority": 100,
9+
"inRepository": true,
10+
"translatorType": 4,
11+
"browserSupport": "gcsb",
12+
"lastUpdated": "2014-09-01 10:21:42"
13+
}
14+
15+
/*
16+
***** BEGIN LICENSE BLOCK *****
17+
18+
Copyright © 2014 Sebastian Karcher
19+
This file is part of Zotero.
20+
21+
Zotero is free software: you can redistribute it and/or modify
22+
it under the terms of the GNU Affero General Public License as published by
23+
the Free Software Foundation, either version 3 of the License, or
24+
(at your option) any later version.
25+
26+
Zotero is distributed in the hope that it will be useful,
27+
but WITHOUT ANY WARRANTY; without even the implied warranty of
28+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29+
GNU Affero General Public License for more details.
30+
31+
You should have received a copy of the GNU Affero General Public License
32+
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
33+
34+
***** END LICENSE BLOCK *****
35+
*/
36+
37+
function detectWeb(doc, url) {
38+
if (url.indexOf("article/citation") != -1) return "journalArticle";
39+
else if (url.indexOf("/search") != -1) return "multiple";
40+
}
41+
42+
function scrape(doc, url) {
43+
var id = url.match(/citation\/(\d+)/)[1];
44+
var token = ZU.xpathText(doc, '(//input[@name="csrf_token"])[1]/@value');
45+
//Z.debug(id);
46+
//Z.debug(token);
47+
var post = "csrf_token=" + token + "&articles=" + id;
48+
var get = "/article/export_for_endnote/";
49+
Zotero.Utilities.HTTP.doPost(get, post, function(text) {
50+
//Z.debug(text);
51+
var translator = Zotero.loadTranslator("import");
52+
// Calling the RIS translator
53+
translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
54+
translator.setString(text);
55+
translator.setHandler("itemDone", function(obj, item) {
56+
item.notes = [];
57+
item.attachments = [{
58+
document: doc,
59+
title: "HAPI Snapshot"
60+
}];
61+
item.complete();
62+
});
63+
translator.translate();
64+
});
65+
66+
}
67+
68+
function doWeb(doc, url) {
69+
var articles = new Array();
70+
var items = {};
71+
if (detectWeb(doc, url) == "multiple") {
72+
var titles = ZU.xpath(doc, '//span[@class="title-link"]');
73+
for (var i = 0; i < titles.length; i++) {
74+
items[ZU.xpathText(titles[i], './@data-title')] = titles[i].textContent;
75+
}
76+
Zotero.selectItems(items, function(items) {
77+
if (!items) {
78+
return true;
79+
}
80+
for (var i in items) {
81+
articles.push("article/citation/" + i);
82+
}
83+
Zotero.Utilities.processDocuments(articles, scrape);
84+
});
85+
} else {
86+
scrape(doc, url);
87+
}
88+
}
89+
/** BEGIN TEST CASES **/
90+
var testCases = [
91+
{
92+
"type": "web",
93+
"url": "http://newstaging.hapi.imagistic.com/article/citation/308849",
94+
"items": [
95+
{
96+
"itemType": "journalArticle",
97+
"creators": [
98+
{
99+
"lastName": "Seveso",
100+
"firstName": "César",
101+
"creatorType": "author"
102+
}
103+
],
104+
"notes": [],
105+
"tags": [
106+
"Peronism",
107+
"Social conflict--Argentina",
108+
"Labor and laboring classes--Argentina--Political activity",
109+
"culture",
110+
"gender",
111+
"memory",
112+
"violence"
113+
],
114+
"seeAlso": [],
115+
"attachments": [
116+
{
117+
"title": "HAPI Snapshot"
118+
}
119+
],
120+
"title": "Millions of Small Battles: The Peronist Resistance in Argentina",
121+
"publicationTitle": "Bulletin of Latin American Research",
122+
"volume": "30",
123+
"issue": "3",
124+
"pages": "313–327",
125+
"url": "http://onlinelibrary.wiley.com/journal/10.1111/%28ISSN%291470-9856/issues",
126+
"date": "2011",
127+
"libraryCatalog": "Hispanic-American Periodical Index (Beta)",
128+
"accessDate": "CURRENT_TIMESTAMP",
129+
"shortTitle": "Millions of Small Battles"
130+
}
131+
]
132+
}
133+
]
134+
/** END TEST CASES **/

0 commit comments

Comments
 (0)