etta.helpers module¶
- call_php_function(func_name, payload, path=None, index_col=None)¶
Call PHP function with given payload and process result.
- Parameters
func_name (str) – Name of PHP function
payload (dict) – key-value pairs of query parameters. MUST contain key ‘output’.
path (str, optional) –
Path to save the result file to. Only relevant if result output is csv, pipe or text.
If path provided is a file, the result will be written to that file.
If path provided is a directory, the file will be saved in the given directory with a default filename.
If path is None, the file will be saved in the current directory with a default filename.
Defaults to None.
index_col (int, str, sequence of int / str, or False, optional) – Only relevant if payload[‘output’] == ‘pandas’. Column(s) to use as the row labels of the
pandas.DataFrameobject, either given as string name or column index. If a sequence of int / str is given, a MultiIndex is used. Defaults to None.
- Returns
if output=’pandas’, a
pandas.DataFrameobject is returned. Else the result is saved to file and the function returns None.- Return type
pandas.DataFrameor None
- create_url(func_name, param_dict)¶
Given a dictionary of query parameters and the PHP function name, form the corresponding URL.
- Parameters
func_name (str) – Name of PHP function.
param_dict (dict) – Key-value pairs of query parameters.
- Returns
the created URL.
- Return type
str
- write_to_path(path, url, default_filename=None)¶
Perform a GET request to the given url and write the result to the given path.
- Parameters
path (str) –
Path to save the result file to. Only relevant if result output is csv, pipe or text.
If path provided is a file, the result will be written to that file.
If path provided is a directory, the file will be saved in the given directory with a default filename.
If path is None, the file will be saved in the current directory with a default filename.
url (str) – Request URL.
default_filename (str, optional) – Default filename of result, used if path points to a directory. Defaults to None.