import socket,fdb,pymysql from pymysql.cursors import DictCursor import pymysql from pymysql.cursors import DictCursor import socket import socket import unicodedata 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_dropbox_path(cesta): hostname = socket.gethostname().strip().upper() if hostname not in ("SESTRA", "LEKAR", "POHODA", "NTBVBHP470G10", "Z230"): print(f"Unknown host: {hostname}") return None # Choose root path based on hostname if hostname in ("NTBVBHP470G10", "Z230"): zacatek = r"U:\Dropbox" else: zacatek = r"Z:\Dropbox" # Normalize text (optional, safer for diacritics) cesta_norm = unicodedata.normalize("NFC", cesta).upper().strip() if cesta_norm == "PŘIJATÁ": return rf"{zacatek}\ordinace\Dokumentace_přijatá" elif cesta_norm == "ZPRACOVANÁ": return rf"{zacatek}\ordinace\Dokumentace_zpracovaná" elif cesta_norm == "REPORTY": return rf"{zacatek}\ordinace\reporty" else: print(f"Unknown cesta: {cesta}") return None def get_path_ciselniky(): hostname = socket.gethostname().strip() 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_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() in ("SESTRA","POHODA"): MEDICUS_CFG = dict( dsn=r"192.168.1.10:m:\medicus\data\medicus.fdb", user="SYSDBA", password="masterkey", charset="win1250", ) elif socket.gethostname().strip()=="LEKAR": MEDICUS_CFG = dict( dsn=r"localhost: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