Skip to content

Python Applications

XHiddenProjects edited this page Aug 13, 2024 · 2 revisions

This will talk about how to make your own Python application

Creating an Application

  1. Create a Python file in the scripts/{app_file.py} and a JSON configuration file in scripts/data/{app_file.json}
  2. In the scripts/{app_file.py} you must have this following syntax
#! <Python compiler here>importos, jsoncurrentPath=os.getcwd() +"/data/{file.json}"withopen(currentPath) asjson_file:
data=json.load(json_file)
finalize= {}
# Content goes hereprint("Content-Type: application/json\n")
print(json.dumps(finalize))

Note: the {app_file.json} is to receive information from the user

Now you have finished the Python portion!

Saving Data

To save the data go to your JavaScript file

APP_FILE_DATA_NAME is the file name of /scripts/data/{app_file.json}. DO NOT PLACE .json at the end of {JSON_FILE_NAME}

importEventsfrom"./Events.js";functionfunctionName(param){// Loads the events classconste=newEvents(),strify=JSON.stringify({"data":"goes here"});// Saving datae.request(window.location.origin+'/WebServerAI/libs/ai_script_data.php?'+encodeURIComponent('dataname={APP_FILE_DATA_NAME}&datasets='+strify));}

Receiving Data

To receive data use this code. This goes into the same function after the Saving Data

constAPI=e.request(window.location.origin+'/WebServerAI/scripts/{app_file.py}',true);returnAPI;

Clone this wiki locally