From f10e046ed110c157c2afb97e7f33cfee35be1660 Mon Sep 17 00:00:00 2001 From: "vladimir.buzalka" Date: Thu, 30 Oct 2025 08:02:09 +0100 Subject: [PATCH] Z230 --- Functions.py | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 Functions.py diff --git a/Functions.py b/Functions.py new file mode 100644 index 0000000..8c5cc9e --- /dev/null +++ b/Functions.py @@ -0,0 +1,98 @@ +import socket,fdb,pymysql +from pymysql.cursors import DictCursor + +import pymysql +from pymysql.cursors import DictCursor +import socket + +def get_path_ciselniky(): + hostname = socket.gethostname().strip().upper() + if hostname in ("NTBVBHP470G10", "Z230"): + return r"u:\Dropbox\!!!Days\Downloads Z230\Pracuji_na\Import" + elif hostname == "SESTRA": + return r"z:\Dropbox\!!!Days\Downloads Z230\Pracuji_na\Import" + else: + print(f"Unknown host: {hostname}") + return None + +def get_reports_folder(): + hostname = socket.gethostname().strip().upper() + if hostname in ("NTBVBHP470G10", "Z230"): + return r"u:\Dropbox\!!!Days\Downloads Z230" + elif hostname in ["SESTRA","POHODA","LEKAR"]: + return r"z:\Dropbox\Ordinace\Reporty" + else: + print(f"Unknown host: {hostname}") + return None + +def get_mysql_connection(cursor_mode=None): + """ + Return a PyMySQL connection. + If cursor_mode == "DICT", return connection with DictCursor. + Otherwise, return default tuple cursor connection. + """ + hostname = socket.gethostname().strip() + + # decide cursor class + cursor_cls = DictCursor if cursor_mode == "DICT" else None + + if hostname in ("NTBVBHP470G10", "Z230"): + MYSQL_CFG = dict( + host="192.168.1.76", + port=3307, + user="root", + password="Vlado9674+", + database="medevio", + autocommit=True, + ) + elif hostname == "SESTRA": + MYSQL_CFG = dict( + host="127.0.0.1", + port=3307, + user="root", + password="Vlado9674+", + database="medevio", + autocommit=True, + ) + else: + print(f"Unknown host: {hostname}") + return None + + # include cursorclass only if we want a dict cursor + if cursor_cls is not None: + MYSQL_CFG["cursorclass"] = cursor_cls + + try: + return pymysql.connect(**MYSQL_CFG) + except pymysql.MySQLError as e: + print(f"MySQL connection failed: {e}") + return None + + +def get_medicus_connection(): + """ + Attempt to create a Firebird connection to the Medicus database. + Returns: + fdb.Connection object on success + None on failure + """ + if socket.gethostname().strip() in ("NTBVBHP470G10","Z230"): + MEDICUS_CFG = dict( + dsn=r"192.168.1.4:z:\medicus 3\data\medicus.fdb", + user="SYSDBA", + password="masterkey", + charset="win1250", + ) + elif socket.gethostname().strip()=="SESTRA": + MEDICUS_CFG = dict( + dsn=r"192.168.1.10:m:\medicus\data\medicus.fdb", + user="SYSDBA", + password="masterkey", + charset="win1250", + ) + + try: + return fdb.connect(**MEDICUS_CFG) + except fdb.fbcore.DatabaseError as e: + print(f"Medicus DB connection failed: {e}") + return None \ No newline at end of file