yourplugin.php 1.21 KB
Newer Older
1
2
3
4
5
<?php
/**
 * You may localized strings in your plugin
 *
 * @package    local_yourplugin
6
 * @copyright 2024 Artem Baranovskyi
7
8
9
 * @license    http://www.gnu.org/copyleft/gpl.html gnu gpl v3 or later
 */

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
$string['pluginname'] = 'New local plugin';

// Path to the Python 3 executable
$python_executable = '/usr/bin/python3';

// Path to the moodlemlbackend script to be executed. First we use test API api.py, then run_LR_SBERT.py
$python_script = '/var/www/html/moodle/api.py';
//$python_script = '/var/www/html/moodle/asyst/Source/Skript/german/run_LR_SBERT.py';

// Python command you want to execute
$python_command = 'print("Hello, world!!!")';

// Formation of a command to execute
//$full_command = $python_executable . ' -c \'' . $python_command . '\'';
$full_command = $python_executable . ' ' . $python_script;

// Execution the command and getting the result
$result = shell_exec($full_command);

// Output the result
echo $result;
// Output the result (assuming moodlemlbackend returns JSON)
$data = json_decode($result, true);
if ($data !== null) {
// Data processing
// Example: output results
    echo "<pre>";
    print_r($data);
    echo "</pre>";
} else {
    echo "Error on data processing from moodlemlbackend!";
}