Commit fee30ffe authored by Mouhamadou Ba's avatar Mouhamadou Ba
Browse files

update

parent 4ac98547
...@@ -9,13 +9,15 @@ rule all: ...@@ -9,13 +9,15 @@ rule all:
rule get_PMCID: rule get_PMCID:
input: input:
doi_file = config["DOIS_FILE"] doi_file = config["DOI_FILE"]
output: output:
pmcid_file = config["PMCID_FILE"] pmcid_file = config["PMCID_FILE"],
doi_folder = directory("data/dois")
params: params:
request_root = config["PMC_REQUEST_ROOT"] request_root = config["PMC_REQUEST_ROOT"]
run: run:
import io import io
import os
import requests import requests
from requests.structures import CaseInsensitiveDict from requests.structures import CaseInsensitiveDict
from requests.utils import requote_uri from requests.utils import requote_uri
...@@ -31,11 +33,15 @@ rule get_PMCID: ...@@ -31,11 +33,15 @@ rule get_PMCID:
headers = CaseInsensitiveDict() headers = CaseInsensitiveDict()
headers["accept"] = "application/json" headers["accept"] = "application/json"
resp = requests.get(request, headers=headers) resp = requests.get(request, headers=headers)
print(resp.status_code) binary = resp.content
Jdata = resp.json() Jdata = json.loads(binary)
print(Jdata) #Jdata = resp.json()
pmcid = Jdata['resultList']['result'][0] pmcid = Jdata["resultList"]["result"][0]["fullTextIdList"]["fullTextId"][0]
data.append(pmcid) data.append(pmcid)
filename = output.doi_folder + '/'+ doi + '.json'
os.makedirs(os.path.dirname(filename), exist_ok=True)
with open(filename, 'w+') as f:
f.write(resp.text)
df = pandas.DataFrame(data, columns=['pmcid']) df = pandas.DataFrame(data, columns=['pmcid'])
df.to_csv(output.pmcid_file, index=False) df.to_csv(output.pmcid_file, index=False)
......
...@@ -11,7 +11,8 @@ rule get_PMCID: ...@@ -11,7 +11,8 @@ rule get_PMCID:
input: input:
doi_file = config["PMID_FILE"] doi_file = config["PMID_FILE"]
output: output:
pmcid_file = config["PMCID_FILE"] pmcid_file = config["PMCID_FILE"],
pmid_folder = directory("data/pmid")
params: params:
request_root = config["PMC_REQUEST_ROOT"] request_root = config["PMC_REQUEST_ROOT"]
run: run:
...@@ -31,11 +32,15 @@ rule get_PMCID: ...@@ -31,11 +32,15 @@ rule get_PMCID:
headers = CaseInsensitiveDict() headers = CaseInsensitiveDict()
headers["accept"] = "application/json" headers["accept"] = "application/json"
resp = requests.get(request, headers=headers) resp = requests.get(request, headers=headers)
print(resp.status_code) binary = resp.content
Jdata = resp.json() Jdata = json.loads(binary)
print(Jdata) #Jdata = resp.json()
pmcid = Jdata['resultList']['result'][0] pmcid = Jdata["resultList"]["result"][0]["fullTextIdList"]["fullTextId"][0]
data.append(pmcid) data.append(pmcid)
filename = output.pmid_folder + '/'+ pmid + '.json'
os.makedirs(os.path.dirname(filename), exist_ok=True)
with open(filename, 'w+') as f:
f.write(resp.text)
df = pandas.DataFrame(data, columns=['pmcid']) df = pandas.DataFrame(data, columns=['pmcid'])
df.to_csv(output.pmcid_file, index=False) df.to_csv(output.pmcid_file, index=False)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment