Changeset 36325


Ignore:
Timestamp:
2022-07-28T23:03:54+12:00 (2 weeks ago)
Author:
davidb
Message:

Code shifted to operate with command-line args

File:
1 edited

Legend:

Unmodified
Added
Removed
  • other-projects/bib-stinky/trunk/doi-stinky/oacore-get-doi.py

    r36323 r36325  
    22
    33# Currently only tested with Python3
     4from __future__ import print_function
    45
    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
    611
    712import os
     
    1621import util
    1722
     23
    1824apiKey = 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
    3125
    3226
     
    4438
    4539
    46 query_args = "api_key="+apiKey+"&q="+urllib.parse.quote_plus("doi:\""+doi+"\"")
    47 query_url  = search_work_url + "?" + query_args
     40def getDOI(doi):
     41   
     42    query_args = "api_key="+apiKey+"&q="+urllib.parse.quote_plus("doi:\""+doi+"\"")
     43    query_url  = search_work_url + "?" + query_args
    4844
    4945
    50 print("query_url="+query_url)
     46    print("query_url="+query_url)
    5147
    52 response = requests.get(query_url, headers=headers)
     48    response = requests.get(query_url, headers=headers)
    5349
    5450
    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)
     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)
    6258
    6359
    64 returned_json_str = response.content
     60    returned_json_str = response.content
     61   
     62    returned_json = json.loads(returned_json_str)
    6563
    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
    7065
    7166
     67       
     68if __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   
    72103# Or consider using their Python API:
    73104#
Note: See TracChangeset for help on using the changeset viewer.