Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try:
from local import WDUSER, WDPASS
except ImportError:
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")
parser = argparse.ArgumentParser(description='run publication creator')
parser.add_argument("ext_id", help="comma-separated list of IDs")
parser.add_argument("--source", help="API to use (crossref or europepmc)", default="crossref")
parser.add_argument("--idtype", help="external id type (doi, pmcid, pmid, etc...)", default="doi")
args = parser.parse_args()
login = wdi_login.WDLogin(WDUSER, WDPASS)
ext_ids = sorted(list(set(map(str.strip, args.ext_id.split(",")))))
id_type = args.idtype
source = args.source
with open("log.txt", "a") as f:
for ext_id in ext_ids:
try:
p = PublicationHelper(ext_id, id_type=id_type, source=source)
qid, warnings, success = p.get_or_create(login)
print("{},{},{},{}".format(ext_id, qid, "|".join(warnings), success))
print("{},{},{},{}".format(ext_id, qid, "|".join(warnings), success), file=f)
sleep(3)
except Exception as e:
print("{},{},{},{}".format(ext_id, None, e, False))
print("{},{},{},{}".format(ext_id, None, e, False), file=f)
def login(user, password):
login_instance = wdi_login.WDLogin(user=user, pwd=password)
def test_query():
login_instance = wdi_login.WDLogin(user=APP.config.WIKIDATA_USER_NAME, pwd=APP.config.WIKIDATA_PASSWORD)
results = wdi_core.WDItemEngine.execute_sparql_query(QUERIES['list-formats'].replace('\n', ''))
return results