From e2fddb327c64cfb5f238c26e481995cc17c3d30d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zieli=C5=84ski?= Date: Fri, 22 Aug 2025 16:17:07 +0200 Subject: [PATCH] test python execute --- modules/EcmInvoiceOuts/ai/test.py | 37 +++++++++++++++++++++++++++++++ modules/EcmInvoiceOuts/test.php | 28 +++++++++++------------ 2 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 modules/EcmInvoiceOuts/ai/test.py mode change 100755 => 100644 modules/EcmInvoiceOuts/test.php diff --git a/modules/EcmInvoiceOuts/ai/test.py b/modules/EcmInvoiceOuts/ai/test.py new file mode 100644 index 00000000..a0c3f0c3 --- /dev/null +++ b/modules/EcmInvoiceOuts/ai/test.py @@ -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() \ No newline at end of file diff --git a/modules/EcmInvoiceOuts/test.php b/modules/EcmInvoiceOuts/test.php old mode 100755 new mode 100644 index 0a6f980f..fc8dc317 --- a/modules/EcmInvoiceOuts/test.php +++ b/modules/EcmInvoiceOuts/test.php @@ -1,18 +1,16 @@ -&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); - - -?> \ No newline at end of file +// Expect a single line with the count +echo trim(implode("\n", $output));