Created
September 24, 2019 05:21
-
-
Save egonw/e95c2fbf3065579b97bd69d5a8c58aa2 to your computer and use it in GitHub Desktop.
Script to add articles to Wikidata with one or more PubMed identifiers or DOIs
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 | |
# | |
# 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