Example of POST vpz/input in Python language

For the simulator ‘wwdm.vpz’ whose Id is 266, enter the Python code/instructions in a Python interpreter.

Example illustrating :

  • modifying begin,

  • modifying duration,

  • modifying some parameters by ‘cname.pname’,

  • compactlist’ as style of presentation,

  • json’ as format,

  • values of type cname.pname as ‘parselect’ :

    value ‘cond_wwdm.A’ to select the parameter named ‘A’ of the condition named ‘cond_wwdm’.

    value ‘cond_wwdm.B’ to select the parameter named ‘B’ of the condition named ‘cond_wwdm’.

    value ‘cond_wwdm.Eb’ to select the parameter named ‘Eb’ of the condition named ‘cond_wwdm’.

    value ‘cond_wwdm.TI’ to select the parameter named ‘TI’ of the condition named ‘cond_wwdm’.

  • with ‘application/json’ as ‘Content-Type’

    Memo

    # -*- coding: utf-8 -*-
    """erecord_cmn.utils.using.send_post_and_receive
    
    Methods that may be used by a user calling the erecord web services from python
    
    """
    
    import pycurl
    import io
    import json
    
    def send_post_and_receive(url, inputdata):
        """Send POST request and return response datas"""
    #
        buffer = io.BytesIO()
        c = pycurl.Curl()
        c.setopt(c.POST, 1)
        c.setopt(c.HTTPHEADER, ['Content-Type: application/json'])
        c.setopt(c.URL, url)
        #c.setopt(c.FOLLOWLOCATION, True)
        json_inputdata = json.dumps( inputdata)
        c.setopt(c.POSTFIELDS, json_inputdata)
        c.setopt(c.WRITEFUNCTION, buffer.write)
        c.perform()
        buffer_str = buffer.getvalue()
        buffer.close()
        buffer_str = buffer_str.decode("utf8")
        responsedata = json.loads(buffer_str)
        return responsedata
    #
    
    
    # Python code :
    
    from __future__ import print_function # python 2.7 version case
    
    #######################
    # request and response
    #######################
    
    inputdata = {"vpz":266, "mode":"compactlist", "format":"json"}
    inputdata["duration"] = 6
    inputdata["begin"] = 2453982.0
    
    # some parameters modification with 'cname.pname'
    inputdata["cond_wwdm.A"] = 0.0064
    inputdata["cond_wwdm.Eb"] = 1.86
    
    inputdata["parselect"] = ["cond_wwdm.A", "cond_wwdm.B", "cond_wwdm.Eb",
                              "cond_wwdm.TI"]
    
    responsedata = send_post_and_receive(
        url="http://erecord.toulouse.inra.fr:8000/vpz/input/",
        inputdata=inputdata)
    
    responsedata
    keys = responsedata.keys()
    keys
    
    ##############################################################
    # responsedata in case of 'compactlist' style of presentation 
    ##############################################################
    
    # duration in 'compactlist' style of presentation
    if "duration" in keys :
        duration_value = responsedata['duration']
        print("duration value : ", duration_value)
    
    # begin in 'compactlist' style of presentation
    if "begin" in keys :
        begin_value = responsedata['begin']
        print("begin value : ", begin_value)
    
    # parameters in 'compactlist' style of presentation
    for par_selection_name in ('cond_wwdm.B',
                               'cond_wwdm.Eb',
                               'cond_wwdm.TI',
                               'cond_wwdm.A'):
        if par_selection_name in keys :
            par_value= json.loads(responsedata[par_selection_name])
            print("parameter selection_name and value :", par_selection_name, par_value)
    
    # conditions identity in 'compactlist' style of presentation
    if "conds" in keys :
        conds = responsedata['conds']
        for cond_selection_name in conds :
            print("condition selection_name : ", cond_selection_name)
    
    # views identity in 'compactlist' style of presentation
    if "views" in keys :
        views = responsedata['views']
        for view_selection_name in views :
            print("view selection_name : ", view_selection_name)
    
    # output datas identity in 'compactlist' style of presentation
    if "outs" in keys :
        outs = responsedata['outs']
        for out_selection_name in outs :
            print("output data selection_name : ", out_selection_name)
    
    pass