source: other-projects/bib-stinky/trunk/doi-stinky/oacore-get-doi.py@ 36323

Last change on this file since 36323 was 36323, checked in by davidb, 21 months ago

Using Python to get DOIs through the Core v3 API

  • Property svn:executable set to *
File size: 1.6 KB
Line 
1#!/usr/bin/env python
2
3# Currently only tested with Python3
4
5from __future__ import print_function
6
7import os
8import sys
9import json
10
11import argparse
12
13import requests
14import urllib.parse
15
16import util
17
18apiKey = util.readKey("oacore-key.txt")
19
20# Example DOI from CORE v3 API:
21# https://api.core.ac.uk/docs/v3#operation/null
22# (scroll down to Discovery)
23#
24oacore_doi="10.1016/0370-2693(96)00910-0"
25
26# Bainbridge et al example, IJDL user-centric approach ...
27stinky_doi="10.1145/1998076.1998084"
28
29print("Selecting Core example DOI: " + oacore_doi)
30doi = oacore_doi
31
32
33# Based on:
34# https://stackoverflow.com/questions/25491090/how-to-use-python-to-execute-a-curl-command
35
36base_url = "https://api.core.ac.uk/v3"
37
38search_work_url = base_url+"/search/works/"
39discover_url = base_url+"/discover"
40
41headers = {
42 'Content-type': 'application/json'
43}
44
45
46query_args = "api_key="+apiKey+"&q="+urllib.parse.quote_plus("doi:\""+doi+"\"")
47query_url = search_work_url + "?" + query_args
48
49
50print("query_url="+query_url)
51
52response = requests.get(query_url, headers=headers)
53
54
55#data = '{}'
56# More work to be done to see if the following can be made to work
57#data = {
58# "api_key": apiKey,
59# "q": "doi:\""+doi+"\""
60#}
61#response = requests.get(query_url, headers=headers, data=data)
62
63
64returned_json_str = response.content
65
66returned_json = json.loads(returned_json_str)
67returned_json_prettyprint = json.dumps(returned_json, indent=2)
68
69print(returned_json_prettyprint)
70
71
72# Or consider using their Python API:
73#
74# https://github.com/oacore/pyoacore
75
76# They also support Java, R and (it looks like) NodeJS
77
78
79# https://core.ac.uk/search?q=doi%3A%2210.1186%2F1471-2458-6-309%22&page=1
Note: See TracBrowser for help on using the repository browser.