def query(cls, query_string, page=1, page_size=25): quoted = quote(query_string, safe="/") qpage = quote(str(page)) qsize = quote(str(page_size)) if qsize is None or qpage is None or quoted is None: raise EuropePMCException(None, "unable to url escape the string") url = app.config.get("EPMC_REST_API") + "search/query=" + query_string url += "&resulttype=core&format=json&page=" + qpage + "&pageSize=" + qsize app.logger.debug("Requesting EPMC metadata from " + url) resp = http.get(url) if resp is None: raise EuropePMCException( message="could not get a response from EPMC") if resp.status_code != 200: raise EuropePMCException(resp) try: j = resp.json() except: raise EuropePMCException( message="could not decode JSON from EPMC response") results = [ models.EPMCMetadata(r) for r in j.get("resultList", {}).get("result", []) ] return results
def test_06_epmc_compliance_data(self): record = models.Record() msg = workflow.WorkflowMessage(record=record) data = json.loads(open(EPMC_MD, "r").read()) epmc_md = epmcmod.EPMCMetadata(data) workflow.extract_metadata(msg, epmc_md) assert record.in_epmc is True assert record.is_oa is False assert len(record.issn) == 1 assert "1471-2121" in record.issn
def test_05_populate_identifiers(self): record = models.Record() msg = workflow.WorkflowMessage(record=record) data = json.loads(open(EPMC_MD, "r").read()) epmc_md = epmcmod.EPMCMetadata(data) workflow.populate_identifiers(msg, epmc_md) assert record.pmcid == "PMC4219345" assert record.pmid == "24279897" assert record.doi == "10.1186/1471-2121-14-52" record.pmcid = "PMC000000" record.pmid = "0000000" del record.doi workflow.populate_identifiers(msg, epmc_md) assert record.pmcid == "PMC000000" assert record.pmid == "0000000" assert record.doi == "10.1186/1471-2121-14-52"
def field_search(cls, field, value, fuzzy=False, page=1): wrap = "\"" if not fuzzy else "" quoted = quote(value, safe="/") qpage = quote(str(page)) if quoted is None or qpage is None: raise EuropePMCException(None, "unable to url escape the string") url = app.config.get("EPMC_REST_API") + "search/query=" + field + ":" + wrap + quoted + wrap url += "&resultType=core&format=json&page=" + qpage app.logger.debug("Requesting EPMC metadata from " + url) resp = http.get(url) if resp is None: raise EuropePMCException(message="could not get a response from EPMC") if resp.status_code != 200: raise EuropePMCException(resp) try: j = resp.json() except: raise EuropePMCException(message="could not decode JSON from EPMC response") results = [models.EPMCMetadata(r) for r in j.get("resultList", {}).get("result", [])] return results
def mock_get_md(*args, **kwargs): md = epmcmod.EPMCMetadata(json.loads(open(EPMC_MD, "r").read())) return md, 1.0