Changeset 36331


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

Code tidy up, and refactoring to have a saveJSON function

Location:
other-projects/bib-stinky/trunk/doi-stinky
Files:
2 edited

Legend:

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

    r36326 r36331  
    55
    66# For more info on the Core V3 API, see:
    7 #     https://api.core.ac.uk/docs/v3
     7#   https://api.core.ac.uk/docs/v3
    88#
    9 # The default DOI value used is based on the one given in the Core V3 API documentation
     9# The default DOI value used below is based on the one given in the Core V3 API documentation
    1010
    1111
     
    2525
    2626
    27 # Based on:
    28 #    https://stackoverflow.com/questions/25491090/how-to-use-python-to-execute-a-curl-command
    29 
    3027base_url = "https://api.core.ac.uk/v3"
    3128
     
    4340    query_url  = search_work_url + "?" + query_args
    4441
     42    # print("query_url="+query_url)
    4543
    46     print("query_url="+query_url)
    47 
     44    # Based on:
     45    #    https://stackoverflow.com/questions/25491090/how-to-use-python-to-execute-a-curl-command
     46   
    4847    response = requests.get(query_url, headers=headers)
    4948
    50 
     49   
    5150    #data = '{}'
    5251    # More work to be done to see if the following can be made to work
  • other-projects/bib-stinky/trunk/doi-stinky/util.py

    r36323 r36331  
    11from __future__ import print_function
    22
     3import json
    34import re
    45import sys
     
    2728
    2829    return key
     30
     31def writeJSON(json_output_filename,returned_json):
     32
     33    returned_json_prettyprint = json.dumps(returned_json, indent=2, ensure_ascii=False)
     34
     35    print("Saving returned JSON output to: " + json_output_filename)
     36
     37    # write output with auto-close file handle
     38    with open(json_output_filename, 'w', encoding="utf8") as fout:
     39        fout.write(returned_json_prettyprint)
Note: See TracChangeset for help on using the changeset viewer.