API Methods

Type Generator

API Interface

Parameters:
code: Source code to analyze.
model: integer value.

CURL Sample

Sample Requests:

Normal Request:

curl  https://smart-scripts.org/py/TypeModel \
-X POST \
-H "Referer: https://smart-scripts.org/py/type" \
-H "Content-Type: application/json" \
-d '{"code":"category = \"AST\"\nsize = 3","model":0}'

Normal Response:

{"result": "category = \"AST\" #  category:str - 0.4278 \nsize = 3 #  size:int - 0.4433 ", "issue": "2 variables analyzed in 0.036 s, one variable at 17.762 ms"}

Request Contains Error:

curl  https://smart-scripts.org/py/TypeModel \
-X POST \
-H "Referer: https://smart-scripts.org/py/type" \
-H "Content-Type: application/json" \
-d '{"code":"category = \"AST\"\\nsize = 3","model":0}'

Error Response:

{"result": "category = \"AST\"\\nsize = 3", "issue": "AST ERROR: unexpected character after line continuation character (<unknown>, line 1)"}

Request not in Json Format:

curl  https://smart-scripts.org/py/TypeModel \
-X POST \
-H "Referer: https://smart-scripts.org/py/type" \
-H "Content-Type: application/json" \
-d 'code":"category = \"AST\"\\nsize = 3","model":0'

Response is a HTML file:

JSONDecodeError at /py/TypeModel
Expecting value: line 1 column 1 (char 0)
Request Method:	POST
Request URL:	https://smart-scripts.org/py/TypeModel
Django Version:	2.2.3
Exception Type:	JSONDecodeError
Exception Value:	
Expecting value: line 1 column 1 (char 0)
Exception Location:	/usr/lib/python3.6/json/decoder.py in raw_decode, line 357
Python Executable:	/usr/local/bin/uwsgi
Python Version:	3.6.8
...

For larger Python Scripts, we can use:

>>> import json
>>> import os
>>> with open("test.py",'r') as f:
...   code = "\n".join(f.readlines())
...
>>> result = json.dumps({'code': code, 'model':0})
>>> with open('result.json','w') as f:
...   f.write(result)
...
>>>

Then, we can send request using:

Request:

curl  https://smart-scripts.org/py/TypeModel \
-X POST \
-H "Referer: https://smart-scripts.org/py/type" \
-H "Content-Type: application/json" \
-d @result.json

Java Sample

We can send POST request using Java API.

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
public class Main {
    public static void main(String[] args) throws Exception {
        Main http = new Main();
        http.sendPost();
    }
    // HTTP POST REQUEST
    private void sendPost() throws Exception {
        String url = "https://smart-scripts.org/py/TypeModel";
        URL obj = new URL(url);
        HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
        con.setRequestMethod("POST");
        con.setRequestProperty("Content-Type", "application/json");
        con.setRequestProperty("Referer", "https://smart-scripts.org/py/type");
        String urlParameters = "{\"code\":\"category = \\\"AST\\\"\\nsize = 3\",\"model\":0}";
        //Send POST Request
        con.setDoOutput(true);
        DataOutputStream wr = new DataOutputStream(con.getOutputStream());
        wr.writeBytes(urlParameters);
        wr.flush();
        wr.close();
        int responseCode = con.getResponseCode();
        System.out.println("\nSending 'POST' request to URL : " + url);
        System.out.println("Post parameters : " + urlParameters);
        System.out.println("Response Code : " + responseCode);
        BufferedReader in = new BufferedReader(
                new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();
        System.out.println(response.toString());

    }

}

Sample Response:

Sending 'POST' request to URL : https://smart-scripts.org/py/TypeModel
Post parameters : {"code":"category = \"AST\"\nsize = 3","model":0}
Response Code : 200
{"result": "category = \"AST\" #  category:str - 0.4278 \nsize = 3 #  size:int - 0.4433 ", "issue": "2 variables analyzed in 0.036 s, one variable at 18.159 ms"}

Process finished with exit code 0

Python Sample

Before we start, we have to install the request package for Python using the following command:

pip install requests

Python Sample code:

# importing the requests library
import requests
import json

def main():
    # defining the api-endpoint
    API_ENDPOINT = "https://smart-scripts.org/py/TypeModel"

    # your source code here
    source_code = ''' 
category = "AST"
size = 3
    '''

    # data to be sent to api
    data = {'code': source_code,
            'model': 0}
    headers = {"Referer": "https://smart-scripts.org/py/type",
               "Content-Type": "application/json"}
    # sending post request and saving response as response object
    r = requests.post(url=API_ENDPOINT,headers = headers , data=json.dumps(data))

    # extracting response text
    resp = r.text
    print(resp)

if __name__ == "__main__":
    main()

Sample Response:

{"result": " \ncategory = \"AST\" #  category:str - 0.4278 \nsize = 3 #  size:int - 0.4433 \n    ", "issue": "2 variables analyzed in 0.036 s, one variable at 17.88 ms"}