Skip to content

Commit

Permalink
Fixed PMC ID retrieval failing
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexJSully committed Aug 8, 2024
1 parent ac62624 commit a19ad76
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/scripts/data-retrieval.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function getPMCList(species = "Arabidopsis thaliana", maxIDs = 1000
/** What is being searched for */
const term = `term=${species}[Organism]&`;
/** Maximum number of publications */
const retmax = `retmax=${maxIDs}&`;
const retmax = `retmax=${maxIDs}`;

/** API's URL */
const url = base + db + term + retmax;
Expand All @@ -54,20 +54,18 @@ export async function getPMCList(species = "Arabidopsis thaliana", maxIDs = 1000
let pmcList = [];

if (data) {
// Parse the XML string with JSDOM
/** JSDOM document */
const dom = new JSDOM(data);
const dom = new JSDOM(data, { contentType: "text/xml" });

if (typeof data === "string" || typeof data === "object") {
// Use JSDOM to parse XML and get all PMCs
// Use JSDOM to parse XML and get all PMCs
pmcList = Array.from(dom.window.document.querySelectorAll("Id")).map((id) => id.textContent);

pmcList = Array.from(dom.window.document.querySelectorAll("Id")).map((id) => id.textContent);

// console feedback
console.log(`Found ${pmcList.length} PMCs for ${species.split("_").join(" ")}...`);
}
console.log(`Found ${pmcList.length} PMCs for ${species.split("_").join(" ")}...`);
return pmcList;
}

// Return PMC list
console.error("No data found...");
return pmcList;
}

Expand Down

0 comments on commit a19ad76

Please sign in to comment.