Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
zuphilip committed Jun 2, 2015
1 parent ca64134 commit 6656fa4
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 126 deletions.
88 changes: 63 additions & 25 deletions Agencia del ISBN.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcs",
"lastUpdated": "2013-02-28 15:02:29"
"lastUpdated": "2015-06-02 06:04:02"
}

function detectWeb(doc, url) {
Expand Down Expand Up @@ -46,31 +46,69 @@ function doWeb(doc, url) {
}


function scrape (doc, url){
var data = new Object();
var rows = doc.evaluate('//div[@class="fichaISBN"]/table/tbody/tr', doc, null, XPathResult.ANY_TYPE, null);
var next_row;
while (next_row = rows.iterateNext()) {
var heading = doc.evaluate('./th', next_row, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;
var value = doc.evaluate('./td', next_row, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;
data[heading.replace(/\W/g, "")] = value;
}
var isbn = Zotero.Utilities.trimInternal(doc.evaluate('//span[@class="cabTitulo"]/strong', doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
var item = new Zotero.Item("book");
item.ISBN = isbn;
item.title = Zotero.Utilities.trimInternal(data['Ttulo']);
item.title= item.title.replace(/\s+:/, ":");
author = data['Autores'];
if (author) {
var authors = author.match(/\b.*,\s+\w+[^([]/g);
for (let aut of authors) {
item.creators.push(Zotero.Utilities.cleanAuthor(Zotero.Utilities.trimInternal(aut), "author", true));
}
function scrape (doc, url){
var data = new Object();
var rows = doc.evaluate('//div[@class="fichaISBN"]/table/tbody/tr', doc, null, XPathResult.ANY_TYPE, null);
var next_row;
while (next_row = rows.iterateNext()) {
var heading = doc.evaluate('./th', next_row, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;
var value = doc.evaluate('./td', next_row, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;
data[heading.replace(/\W/g, "")] = value;
}
var isbn = Zotero.Utilities.trimInternal(doc.evaluate('//span[@class="cabTitulo"]/strong', doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
var item = new Zotero.Item("book");
item.ISBN = isbn;
item.title = Zotero.Utilities.trimInternal(data['Ttulo']);
item.title= item.title.replace(/\s+:/, ":");
author = data['Autores'];
if (author) {
var authors = author.match(/\b.*,\s+\w+[^([]/g);
for (var i=0; i<authors.length; i++) {
var aut = Zotero.Utilities.trimInternal(authors[i]);
item.creators.push(Zotero.Utilities.cleanAuthor(aut, "author", true));
}
if (data['Publicacin']) item.publisher = Zotero.Utilities.trimInternal(data['Publicacin']);
if (data['FechaEdicin']) item.date = Zotero.Utilities.trimInternal(data['FechaEdicin']);
item.complete();
}
if (data['Publicacin']) item.publisher = Zotero.Utilities.trimInternal(data['Publicacin']);
if (data['FechaEdicin']) item.date = Zotero.Utilities.trimInternal(data['FechaEdicin']);
item.complete();
}

/** BEGIN TEST CASES **/
var testCases = []
var testCases = [
{
"type": "web",
"url": "http://www.mcu.es/webISBN/tituloDetalle.do?sidTitul=292802&action=busquedaInicial&noValidating=true&POS=0&MAX=50&TOTAL=0&prev_layout=busquedaisbn&layout=busquedaisbn&language=es",
"items": [
{
"itemType": "book",
"title": "La actitud intencional",
"creators": [
{
"firstName": "Daniel",
"lastName": "Dennett",
"creatorType": "author"
},
{
"firstName": "Daniel",
"lastName": "Dennett",
"creatorType": "author"
},
{
"firstName": "Gabriela",
"lastName": "Ventureira",
"creatorType": "author"
}
],
"date": "03/1991",
"ISBN": "9788474323955",
"libraryCatalog": "Agencia del ISBN",
"publisher": "GEDISA",
"attachments": [],
"tags": [],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/
32 changes: 17 additions & 15 deletions Ancestry.com US Federal Census.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"translatorID":"0dda3f89-15de-4479-987f-cc13f1ba7999",
"translatorType":4,
"label":"Ancestry.com US Federal Census",
"creator":"Elena Razlogova",
"target":"^https?://search.ancestry.com/(.*)usfedcen|1890orgcen|1910uscenindex",
"minVersion":"1.0.0b4.r1",
"maxVersion":"",
"priority":100,
"inRepository":true,
"lastUpdated":"2011-01-11 04:31:00"
"translatorID": "0dda3f89-15de-4479-987f-cc13f1ba7999",
"label": "Ancestry.com US Federal Census",
"creator": "Elena Razlogova",
"target": "^https?://search.ancestry.com/(.*)usfedcen|1890orgcen|1910uscenindex",
"minVersion": "1.0.0b4.r1",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "g",
"lastUpdated": "2015-06-02 10:57:09"
}

function detectWeb(doc, url) {
Expand All @@ -18,7 +19,7 @@ function detectWeb(doc, url) {
} : null;

var result = doc.evaluate('//div[@class="g_container"]/div[@class="g_panelWrap"]/div[@class="g_panelCore"]/div[@class="s_container"]/div[@class="p_rsltList"]', doc, nsResolver,
XPathResult.ANY_TYPE, null).iterateNext();
XPathResult.ANY_TYPE, null).iterateNext();

var rows = doc.evaluate('//div[@class="g_container"]/div[@class="g_panelWrap"]/div[@class="g_panelCore"]/div[@class="s_container"]/div[@class="p_rsltList"]/table/tbody/tr[@class="tblrow record"]',
doc, nsResolver, XPathResult.ANY_TYPE, null);
Expand Down Expand Up @@ -70,7 +71,8 @@ function scrape(doc) {
info = info.toString();
var data = new Array();
var parts = info.split(/[?&]/);
for (let part of parts) {
for (var i=0; i<parts.length; i++) {
var part = parts[i];
var index = part.indexOf("=");
if(index !== -1) {
data[part.substr(0, index)] = part.substr(index+1);
Expand Down Expand Up @@ -103,9 +105,9 @@ function scrape(doc) {
var censusNo = "";
var censusNos = new Array("1790", "First", "1800", "Second", "1810", "Third", "1820", "Fourth", "1830", "Fifth", "1840", "Sixth", "1850", "Seventh", "1860", "Eighth", "1870", "Ninth",
"1880", "Tenth", "1890", "Eleventh", "1900", "Twelfth", "1910", "Thirteenth", "1920", "Fourteenth", "1930", "Fifteenth")
for(var i in censusNos) {
if(censusYear == 1) { censusNo = censusNos[i] };
if(censusNos[i] == year) { censusYear = 1 } else {censusYear= 0 };
for(var j in censusNos) {
if(censusYear == 1) { censusNo = censusNos[j] };
if(censusNos[j] == year) { censusYear = 1 } else {censusYear= 0 };
}

//begin adding item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2012-03-03 23:29:34"
"lastUpdated": "2015-06-02 05:58:49"
}

function detectWeb(doc, url) {
Expand Down Expand Up @@ -57,7 +57,8 @@ function doWeb(doc, url) {
for (var tag in metaTags) {
if (tag == "DC.creator") {
var authors = data['DC.creator'].split(";");
for (let aut of authors) {
for (var i=0; i<authors.length; i++) {
var aut = authors[i];
aut = aut.replace(/^([^,]+),\s+(.*)$/, "$2 $1");
item.creators.push(Zotero.Utilities.cleanAuthor(aut, "author"));
}
Expand Down
7 changes: 4 additions & 3 deletions Biblio.com.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2014-04-28 19:32:32"
"lastUpdated": "2015-06-02 08:32:10"
}

function detectWeb(doc, url) {
Expand Down Expand Up @@ -43,7 +43,7 @@ function scrape(doc, url) {
var content = doc.evaluate('//div[@id="description"]/ul/li', doc, null, XPathResult.ANY_TYPE, null);
var xPathCount = doc.evaluate('count (//div[@id="description"]/ul/li)', doc, null, XPathResult.ANY_TYPE, null);

for (i=0; i<xPathCount.numberValue; i++) {
for (var i=0; i<xPathCount.numberValue; i++) {
contents = content.iterateNext().textContent.split(": ");
if (contents.length>1){
fieldTitle = contents[0].replace(/\s*/g, '');
Expand All @@ -56,7 +56,8 @@ function scrape(doc, url) {
if (authors.match(/\w/)) {
authors = authors.replace(/^\s*by/, "");
multiAuthors = authors.split(";");
for (let aut of multiAuthors) {
for (var j=0; j<multiAuthors.length; j++) {
var aut = multiAuthors[j];
newItem.creators.push(Zotero.Utilities.cleanAuthor(aut, "author", aut.match(/,/)));
}
}
Expand Down
5 changes: 3 additions & 2 deletions Bryn Mawr Classical Review.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2013-01-23 12:41:08"
"lastUpdated": "2015-06-02 10:52:41"
}

function detectWeb(doc, url) {
Expand Down Expand Up @@ -67,7 +67,8 @@ function doWeb(doc, url) {
var splitRe = new RegExp(title);
var authors = data.split(splitRe)[0].replace(/\([^)]+\)/, "").split(/(,|and)\s+/);
Zotero.debug(authors);
for (let aut of authors) {
for (var i=0; i<authors.length; i++) {
var aut = authors[i];
if (aut.match(/\w/) && (aut != "and")) {
item.creators.push(Zotero.Utilities.cleanAuthor(aut, "reviewedAuthor"));
}
Expand Down
10 changes: 6 additions & 4 deletions Columbia University Press.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2015-06-01 21:47:01"
"lastUpdated": "2015-06-02 10:55:49"
}

function detectWeb(doc, url) {
Expand Down Expand Up @@ -55,11 +55,12 @@ function doWeb(doc, url) {

function scrape(doc, url) {
var item = new Zotero.Item("book");
item.title = Zotero.Utilities.trimInternal(ZU.xpathText(doc, '//h1[@id="_booktitle"]'));Z.debug(title);
item.title = Zotero.Utilities.trimInternal(ZU.xpathText(doc, '//h1[@id="_booktitle"]'));
var authors = Zotero.Utilities.trimInternal(ZU.xpathText(doc, '//p[@id="_authors"]'));
//we parse the author string - first assign roles and then split multiple authors in those groups.
var auts = authors.split(/;/);
for (let aut of auts) {
for (var i=0; i<auts.length; i++) {
var aut = auts[i];
if (aut.match(/Edited/)) {
var autType = "editor";
aut = aut.replace(/Edited (by)?/, "");
Expand All @@ -70,7 +71,8 @@ function scrape(doc, url) {
var autType = "author";
}
aut = aut.split(/\band\b|,/);
for (let aut2 of aut) {
for (var j=0; j<aut.length; j++) {
var aut2 = aut[j];
item.creators.push(Zotero.Utilities.cleanAuthor(aut2, autType));
}
}
Expand Down
Loading

0 comments on commit 6656fa4

Please sign in to comment.