cofdb_submit/main.py
def on_click_fetch(event):
    """Get metadata for DOI, and return an error if the DOI is not valid (no metadata found)."""
    import dateutil
    from crossref.restful import Works
    import json

    # turn the "Add paper" primary, to remember clicking it again!
    btn_add_paper.button_type = 'primary'

    # Input DOI: (1) if empty use test DOI (2) If Angewandte German Edition, change with International Edition
    inp_doi.value = inp_doi.value.replace("ange","anie") or "10.1021/jacs.9b01891"

    works = Works()
    print("Querying Crossref API for doi {} (this can take several seconds, depending on the server...)".format(inp_doi.value))
    metadata = works.doi(inp_doi.value)
    print("Query done!")
    #print(json.dumps(metadata,sort_keys=True, indent=4)) # Use for debug!

    if not metadata:
        btn_doi.button_type = 'danger'
        inp_title.value = inp_year.value = inp_reference.value = inp_paper_id.value = "ERROR: wrong/missing DOI."
        return

    inp_title.value = str(metadata['title'][0])
    journal = str(metadata['short-container-title'][0])

    if 'volume' in metadata:
        already_in_issue = True
        volume = metadata['volume']
        if 'published-print' in metadata: # ACS, wiley
            year = str(metadata['published-print']['date-parts'][0][0])
        elif 'created' in metadata: # RSC
            year = str(metadata['created']['date-parts'][0][0])
        else:
            year = 'ERROR: year not found.'
    else: # not yet in an issue: assuming that it will be published at the same year of today
        already_in_issue = False
        year = str(datetime.datetime.now().year)

    inp_year.value = year

    if already_in_issue:
        if 'page' in metadata: # most of the journals
            inp_reference.value = "{}, {}, {}, {}".format(journal, year, volume, metadata['page'])
        else:  # NatComm or not yet in an issue
            inp_reference.value = "{}, {}, {}".format(journal, year, volume)
    else:
        inp_reference.value = "{}, {}, {}".format(journal, year, "in press")
    inp_paper_id.value = mint_paper_id(doi=inp_doi.value, year=inp_year.value)
    btn_doi.button_type = 'success'
Get metadata for DOI, and return an error if the DOI is not valid (no metadata found).
Get metadata for DOI, and return an error if the DOI is not valid (no metadata found).
Get metadata for DOI and return an error if the DOI is not valid ( no metadata found ) .
def on_click_fetch(event):
    import dateutil
    from crossref.restful import Works
    import json
    btn_add_paper.button_type = 'primary'
    inp_doi.value = inp_doi.value.replace("ange","anie") or "10.1021/jacs.9b01891"
    works = Works()
    print("Querying Crossref API for doi {} (this can take several seconds, depending on the server...)".format(inp_doi.value))
    metadata = works.doi(inp_doi.value)
    print("Query done!")
    if not metadata:
        btn_doi.button_type = 'danger'
        inp_title.value = inp_year.value = inp_reference.value = inp_paper_id.value = "ERROR: wrong/missing DOI."
        return
    inp_title.value = str(metadata['title'][0])
    journal = str(metadata['short-container-title'][0])
    if 'volume' in metadata:
        already_in_issue = True
        volume = metadata['volume']
        if 'published-print' in metadata: 
            year = str(metadata['published-print']['date-parts'][0][0])
        elif 'created' in metadata: 
            year = str(metadata['created']['date-parts'][0][0])
        else:
            year = 'ERROR: year not found.'
    else: 
        already_in_issue = False
        year = str(datetime.datetime.now().year)
    inp_year.value = year
    if already_in_issue:
        if 'page' in metadata: 
            inp_reference.value = "{}, {}, {}, {}".format(journal, year, volume, metadata['page'])
        else:  
            inp_reference.value = "{}, {}, {}".format(journal, year, volume)
    else:
        inp_reference.value = "{}, {}, {}".format(journal, year, "in press")
    inp_paper_id.value = mint_paper_id(doi=inp_doi.value, year=inp_year.value)
    btn_doi.button_type = 'success'
def on_click_fetch ( event ) : import dateutil from crossref . restful import Works import json btn_add_paper . button_type = 'primary' inp_doi . value = inp_doi . value . replace ( "ange" , "anie" ) or "10.1021/jacs.9b01891" works = Works ( ) print ( "Querying Crossref API for doi {} (this can take several seconds, depending on the server...)" . format ( inp_doi . value ) ) metadata = works . doi ( inp_doi . value ) print ( "Query done!" ) if not metadata : btn_doi . button_type = 'danger' inp_title . value = inp_year . value = inp_reference . value = inp_paper_id . value = "ERROR: wrong/missing DOI." return inp_title . value = str ( metadata [ 'title' ] [ 0 ] ) journal = str ( metadata [ 'short-container-title' ] [ 0 ] ) if 'volume' in metadata : already_in_issue = True volume = metadata [ 'volume' ] if 'published-print' in metadata : year = str ( metadata [ 'published-print' ] [ 'date-parts' ] [ 0 ] [ 0 ] ) elif 'created' in metadata : year = str ( metadata [ 'created' ] [ 'date-parts' ] [ 0 ] [ 0 ] ) else : year = 'ERROR: year not found.' else : already_in_issue = False year = str ( datetime . datetime . now ( ) . year ) inp_year . value = year if already_in_issue : if 'page' in metadata : inp_reference . value = "{}, {}, {}, {}" . format ( journal , year , volume , metadata [ 'page' ] ) else : inp_reference . value = "{}, {}, {}" . format ( journal , year , volume ) else : inp_reference . value = "{}, {}, {}" . format ( journal , year , "in press" ) inp_paper_id . value = mint_paper_id ( doi = inp_doi . value , year = inp_year . value ) btn_doi . button_type = 'success'
Get metadata for DOI, and return an error if the DOI is not valid (no metadata found).
Get metadata for DOI and return an error if the DOI is not valid ( no metadata found ) .
"""Get metadata for DOI, and return an error if the DOI is not valid (no metadata found).""" # turn the "Add paper" primary, to remember clicking it again! # Input DOI: (1) if empty use test DOI (2) If Angewandte German Edition, change with International Edition #print(json.dumps(metadata,sort_keys=True, indent=4)) # Use for debug! # ACS, wiley # RSC # not yet in an issue: assuming that it will be published at the same year of today # most of the journals # NatComm or not yet in an issue
event