This commit is contained in:
michaela.buzalkova
2025-09-28 15:33:05 +02:00
parent aa52a70bcc
commit adfa781cd0
5 changed files with 118 additions and 36 deletions

View File

@@ -43,21 +43,33 @@ def get_medicus_connection():
print(f"Medicus DB connection failed: {e}")
return None
# -------- MySQL (Medevio, etc.) -------
MYSQL_CFG = dict(
host="192.168.1.76",
port=3307,
user="root",
password="Vlado9674+",
database="medevio",
cursorclass=DictCursor,
autocommit=True, # or False if you prefer manual commit
)
def get_mysql_connection():
"""
Return a PyMySQL connection or None if the connection fails.
"""
if socket.gethostname().strip() == "NTBVBHP470G10":
MYSQL_CFG = dict(
host="192.168.1.76",
port=3307,
user="root",
password="Vlado9674+",
database="medevio",
cursorclass=DictCursor,
autocommit=True, # or False if you prefer manual commit
)
elif socket.gethostname().strip() == "SESTRA":
MYSQL_CFG = dict(
host="127.0.0.1",
port=3307,
user="root",
password="Vlado9674+",
database="medevio",
cursorclass=DictCursor,
autocommit=True, # or False if you prefer manual commit
)
try:
return pymysql.connect(**MYSQL_CFG)
except pymysql.MySQLError as e:
@@ -73,15 +85,7 @@ EP_STAV = "https://prod.b2b.vzp.cz/B2BProxy/HttpProxy/stavPojisteniB2B"
SOAP_NS = "http://schemas.xmlsoap.org/soap/envelope/"
NS_STAV = "http://xmlns.gemsystem.cz/stavPojisteniB2B"
MYSQL_CFG = {
"host": os.getenv("MYSQL_HOST", "192.168.1.76"),
"port": int(os.getenv("MYSQL_PORT", "3307")),
"user": os.getenv("MYSQL_USER", "root"),
"password": os.getenv("MYSQL_PASSWORD", "Vlado9674+"),
"database": os.getenv("MYSQL_DB", "medevio"),
"cursorclass": DictCursor,
"autocommit": False,
}
# ======== HELPERS ========
def normalize_rc(rc: str) -> str:
@@ -153,7 +157,7 @@ def save_stav_pojisteni(rc: str, k_datu: str, parsed: dict, response_xml: str) -
VALUES
(%(rc)s, %(k_datu)s, %(stav)s, %(kod_pojistovny)s, %(nazev_pojistovny)s, %(pojisteni_kod)s, %(stav_vyrizeni)s, %(response_xml)s)
"""
conn = pymysql.connect(**MYSQL_CFG)
conn = get_mysql_connection()
try:
with conn.cursor() as cur:
cur.execute(sql, payload)