Changeset 36325 for other-projects
- Timestamp:
- 2022-07-28T23:03:54+12:00 (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/bib-stinky/trunk/doi-stinky/oacore-get-doi.py
r36323 r36325 2 2 3 3 # Currently only tested with Python3 4 from __future__ import print_function 4 5 5 from __future__ import print_function 6 # For more info on the Core V3 API, see: 7 # https://api.core.ac.uk/docs/v3 8 # 9 # The default DOI value used is based on the one given in the Core V3 API documentation 10 6 11 7 12 import os … … 16 21 import util 17 22 23 18 24 apiKey = util.readKey("oacore-key.txt") 19 20 # Example DOI from CORE v3 API:21 # https://api.core.ac.uk/docs/v3#operation/null22 # (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_doi31 25 32 26 … … 44 38 45 39 46 query_args = "api_key="+apiKey+"&q="+urllib.parse.quote_plus("doi:\""+doi+"\"") 47 query_url = search_work_url + "?" + query_args 40 def getDOI(doi): 41 42 query_args = "api_key="+apiKey+"&q="+urllib.parse.quote_plus("doi:\""+doi+"\"") 43 query_url = search_work_url + "?" + query_args 48 44 49 45 50 print("query_url="+query_url)46 print("query_url="+query_url) 51 47 52 response = requests.get(query_url, headers=headers)48 response = requests.get(query_url, headers=headers) 53 49 54 50 55 #data = '{}'56 # More work to be done to see if the following can be made to work57 #data = {58 # "api_key": apiKey,59 # "q": "doi:\""+doi+"\""60 #}61 #response = requests.get(query_url, headers=headers, data=data)51 #data = '{}' 52 # More work to be done to see if the following can be made to work 53 #data = { 54 # "api_key": apiKey, 55 # "q": "doi:\""+doi+"\"" 56 #} 57 #response = requests.get(query_url, headers=headers, data=data) 62 58 63 59 64 returned_json_str = response.content 60 returned_json_str = response.content 61 62 returned_json = json.loads(returned_json_str) 65 63 66 returned_json = json.loads(returned_json_str) 67 returned_json_prettyprint = json.dumps(returned_json, indent=2) 68 69 print(returned_json_prettyprint) 64 return returned_json 70 65 71 66 67 68 if __name__ == "__main__": 69 70 parser = argparse.ArgumentParser() 71 #parser.add_argument('--sheetname', help="The name of the sheet within the Excel file to extractc data from") 72 #parser.add_argument('--votingtype', choices=["J","T", "JT"], help="Filter to only J=Jury, T=Tele cast votes, JT=Combined jury and tele votes") 73 parser.add_argument('doi', nargs='?') 74 parser.add_argument('output-file.json', nargs='?') 75 76 args = parser.parse_args() 77 78 #sheetname = getattr(args,'sheetname'); 79 #voting_type = getattr(args,'votingtype'); 80 81 doi = getattr(args,'doi'); 82 if (doi == None): 83 oacore_example_doi="10.1016/0370-2693(96)00910-0" 84 85 # Bainbridge et al example, IJDL user-centric approach ... 86 stinky_doi="10.1145/1998076.1998084" 87 88 print("As a default, selecting Core example DOI: " + oacore_example_doi) 89 doi = oacore_example_doi 90 91 json_output_filename = getattr(args,'output-file.json'); 92 if (json_output_filename == None): 93 encoded_doi = urllib.parse.quote_plus(doi) 94 json_output_filename = "oacore-"+encoded_doi+".json" 95 96 returned_json = getDOI(doi) 97 returned_json_prettyprint = json.dumps(returned_json, indent=2) 98 99 print(returned_json_prettyprint) 100 101 102 72 103 # Or consider using their Python API: 73 104 #
Note:
See TracChangeset
for help on using the changeset viewer.