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()
|
||||
Reference in New Issue
Block a user