Last active
December 14, 2019 12:06
-
-
Save egonw/7f510fc51070414e0fe10e84dbf8c603 to your computer and use it in GitHub Desktop.
Tool that takes a DOI and PubMed ID and creates Quickstatements for Wikidata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (C) 2019 Andra Waagmeester | |
# 2019 Egon Willighagen | |
# | |
# If you used this code, please cite this paper: https://www.biorxiv.org/content/10.1101/799684v1 | |
# | |
# Install first (see https://pypi.org/project/wikidataintegrator/): | |
# | |
# pip install wikidataintegrator | |
# | |
# MIT License | |
from wikidataintegrator import wdi_core, wdi_login, wdi_helpers | |
import os | |
import sys | |
if "WDUSER" in os.environ and "WDPASS" in os.environ: | |
WDUSER = os.environ['WDUSER'] | |
WDPASS = os.environ['WDPASS'] | |
else: | |
raise ValueError("WDUSER and WDPASS must be specified in local.py or as environment variables") | |
if not sys.argv[1]: | |
raise ValueError("An input identifier (DOI or PubMed) should be provided") | |
login = wdi_login.WDLogin(WDUSER, WDPASS) | |
def processIdentifier(arg): | |
if arg.startswith("10."): | |
doi = arg | |
qid = wdi_helpers.PublicationHelper( | |
doi, id_type="doi", | |
source="crossref").get_or_create(login if True else None) | |
print(doi + ": " + str(qid)) | |
else: | |
pmid = arg | |
qid = wdi_helpers.PublicationHelper( | |
pmid, id_type="pmid", | |
source="europepmc").get_or_create(login if True else None) | |
print(pmid + ": " + str(qid)) | |
if (len(sys.argv)==2 and sys.argv[1] == "--"): | |
print("reading from stdin\n") | |
for line in sys.stdin: | |
processIdentifier(line.rstrip()) | |
elif len(sys.argv)>1: | |
for x in sys.argv: | |
processIdentifier(str(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example use: