test python execute
This commit is contained in:
37
modules/EcmInvoiceOuts/ai/test.py
Normal file
37
modules/EcmInvoiceOuts/ai/test.py
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import sys
|
||||
|
||||
try:
|
||||
import mysql.connector
|
||||
except Exception as e:
|
||||
sys.stderr.write("MySQL connector not available: %s\n" % e)
|
||||
sys.exit(1)
|
||||
|
||||
def getenv(key, default=None):
|
||||
return os.environ.get(key, default)
|
||||
|
||||
def main():
|
||||
cfg = {
|
||||
"host": getenv("MYSQL_HOST", "twinpol-mysql56"),
|
||||
"user": getenv("MYSQL_USER", "root"),
|
||||
"password": getenv("MYSQL_PASSWORD", "rootpassword"),
|
||||
"database": getenv("MYSQL_DATABASE", "preDb_0dcc87940d3655fa574b253df04ca1c3"),
|
||||
"port": int(getenv("MYSQL_PORT", "3306")),
|
||||
}
|
||||
|
||||
try:
|
||||
cnx = mysql.connector.connect(**cfg)
|
||||
cur = cnx.cursor()
|
||||
cur.execute("SELECT COUNT(*) FROM ecminvoiceouts WHERE YEAR(register_date)=2025")
|
||||
row = cur.fetchone()
|
||||
count = int(row[0]) if row and row[0] is not None else 0
|
||||
print(count)
|
||||
cur.close()
|
||||
cnx.close()
|
||||
except Exception as e:
|
||||
sys.stderr.write("Query error: %s\n" % e)
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
26
modules/EcmInvoiceOuts/test.php
Executable file → Normal file
26
modules/EcmInvoiceOuts/test.php
Executable file → Normal file
@@ -1,18 +1,16 @@
|
||||
<?php
|
||||
// Runs the Python script, waits for completion, and returns its output.
|
||||
|
||||
$cmd = 'python3 /var/www/html/modules/EcmInvoiceOuts/ai/test.py';
|
||||
$output = [];
|
||||
$returnVar = 0;
|
||||
exec($cmd . ' 2>&1', $output, $returnVar);
|
||||
|
||||
if ($returnVar !== 0) {
|
||||
http_response_code(500);
|
||||
echo "Error running Python script:\n" . implode("\n", $output);
|
||||
exit;
|
||||
}
|
||||
|
||||
$url='http://damznac.pl/login'; // Specify your url
|
||||
$data= array('username'=>'lol','api_key'=>'val'); // Add parameters in key value
|
||||
$ch = curl_init(); // Initialize cURL
|
||||
curl_setopt($ch, CURLOPT_URL,$url);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
|
||||
|
||||
//curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$return= curl_exec($ch);
|
||||
var_dump($return);
|
||||
curl_close($ch);
|
||||
|
||||
|
||||
?>
|
||||
// Expect a single line with the count
|
||||
echo trim(implode("\n", $output));
|
||||
|
||||
Reference in New Issue
Block a user