Planetensichtbarkeit auf PY umgestellt
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
ini_set('display_errors', '1');
|
||||
error_reporting(E_ALL);
|
||||
session_start();
|
||||
require_once __DIR__ . '/python_api.php';
|
||||
|
||||
$loggedIn = isset($_SESSION['user_id']);
|
||||
$pageTitle = 'Astronomische Umrechnungen';
|
||||
@@ -16,47 +17,6 @@ function h(?string $value): string
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
function runPythonApi(string $action, array $args): array
|
||||
{
|
||||
$scriptPath = __DIR__ . '/py/api.py';
|
||||
$pythonCandidates = PHP_OS_FAMILY === 'Windows'
|
||||
? ['python', 'py']
|
||||
: ['/usr/bin/python3', '/usr/bin/python', 'python3', 'python'];
|
||||
|
||||
$escapedArguments = array_map('escapeshellarg', array_merge([$scriptPath, $action], $args));
|
||||
$lastError = 'Python konnte nicht gestartet werden.';
|
||||
|
||||
foreach ($pythonCandidates as $pythonBinary) {
|
||||
$command = $pythonBinary . ' ' . implode(' ', $escapedArguments) . ' 2>&1';
|
||||
$output = [];
|
||||
$resultCode = 0;
|
||||
exec($command, $output, $resultCode);
|
||||
|
||||
$joined = trim(implode("\n", $output));
|
||||
$decoded = json_decode($joined, true);
|
||||
|
||||
if (is_array($decoded)) {
|
||||
return [
|
||||
'ok' => (bool) ($decoded['ok'] ?? false),
|
||||
'data' => $decoded,
|
||||
'raw' => $joined,
|
||||
'command' => $command,
|
||||
];
|
||||
}
|
||||
|
||||
if ($joined !== '') {
|
||||
$lastError = $joined;
|
||||
} elseif ($resultCode !== 0) {
|
||||
$lastError = 'Fehlercode ' . $resultCode . ' bei ' . $pythonBinary;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'ok' => false,
|
||||
'error' => $lastError,
|
||||
];
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && (string) ($_POST['ajax'] ?? '') === '1') {
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user