1 | #!/usr/bin/env python
|
---|
2 |
|
---|
3 | # Currently only tested with Python3
|
---|
4 |
|
---|
5 | from __future__ import print_function
|
---|
6 |
|
---|
7 | import os
|
---|
8 | import sys
|
---|
9 | import json
|
---|
10 |
|
---|
11 | import argparse
|
---|
12 |
|
---|
13 | import requests
|
---|
14 | import urllib.parse
|
---|
15 |
|
---|
16 | import util
|
---|
17 |
|
---|
18 | apiKey = 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 | #
|
---|
24 | oacore_doi="10.1016/0370-2693(96)00910-0"
|
---|
25 |
|
---|
26 | # Bainbridge et al example, IJDL user-centric approach ...
|
---|
27 | stinky_doi="10.1145/1998076.1998084"
|
---|
28 |
|
---|
29 | print("Selecting Core example DOI: " + oacore_doi)
|
---|
30 | doi = oacore_doi
|
---|
31 |
|
---|
32 |
|
---|
33 | # Based on:
|
---|
34 | # https://stackoverflow.com/questions/25491090/how-to-use-python-to-execute-a-curl-command
|
---|
35 |
|
---|
36 | base_url = "https://api.core.ac.uk/v3"
|
---|
37 |
|
---|
38 | search_work_url = base_url+"/search/works/"
|
---|
39 | discover_url = base_url+"/discover"
|
---|
40 |
|
---|
41 | headers = {
|
---|
42 | 'Content-type': 'application/json'
|
---|
43 | }
|
---|
44 |
|
---|
45 |
|
---|
46 | query_args = "api_key="+apiKey+"&q="+urllib.parse.quote_plus("doi:\""+doi+"\"")
|
---|
47 | query_url = search_work_url + "?" + query_args
|
---|
48 |
|
---|
49 |
|
---|
50 | print("query_url="+query_url)
|
---|
51 |
|
---|
52 | response = 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 |
|
---|
64 | returned_json_str = response.content
|
---|
65 |
|
---|
66 | returned_json = json.loads(returned_json_str)
|
---|
67 | returned_json_prettyprint = json.dumps(returned_json, indent=2)
|
---|
68 |
|
---|
69 | print(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
|
---|