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

update

parent 4ac98547
......@@ -9,13 +9,15 @@ rule all:
rule get_PMCID:
input:
doi_file = config["DOIS_FILE"]
doi_file = config["DOI_FILE"]
output:
pmcid_file = config["PMCID_FILE"]
pmcid_file = config["PMCID_FILE"],
doi_folder = directory("data/dois")
params:
request_root = config["PMC_REQUEST_ROOT"]
run:
import io
import os
import requests
from requests.structures import CaseInsensitiveDict
from requests.utils import requote_uri
......@@ -31,11 +33,15 @@ rule get_PMCID:
headers = CaseInsensitiveDict()
headers["accept"] = "application/json"
resp = requests.get(request, headers=headers)
print(resp.status_code)
Jdata = resp.json()
print(Jdata)
pmcid = Jdata['resultList']['result'][0]
binary = resp.content
Jdata = json.loads(binary)
#Jdata = resp.json()
pmcid = Jdata["resultList"]["result"][0]["fullTextIdList"]["fullTextId"][0]
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.to_csv(output.pmcid_file, index=False)
......
......@@ -11,7 +11,8 @@ rule get_PMCID:
input:
doi_file = config["PMID_FILE"]
output:
pmcid_file = config["PMCID_FILE"]
pmcid_file = config["PMCID_FILE"],
pmid_folder = directory("data/pmid")
params:
request_root = config["PMC_REQUEST_ROOT"]
run:
......@@ -31,11 +32,15 @@ rule get_PMCID:
headers = CaseInsensitiveDict()
headers["accept"] = "application/json"
resp = requests.get(request, headers=headers)
print(resp.status_code)
Jdata = resp.json()
print(Jdata)
pmcid = Jdata['resultList']['result'][0]
binary = resp.content
Jdata = json.loads(binary)
#Jdata = resp.json()
pmcid = Jdata["resultList"]["result"][0]["fullTextIdList"]["fullTextId"][0]
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.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