From 7eec4caf827b00700745a3c2d6bd3d4ad8f563b5 Mon Sep 17 00:00:00 2001 From: Vladimir Buzalka Date: Sun, 28 Sep 2025 14:25:20 +0200 Subject: [PATCH] notebookVB --- 01 testik.py | 3 ++- 03 Vyber.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 04 testik.py | 7 +++++++ functions.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 03 Vyber.py create mode 100644 04 testik.py diff --git a/01 testik.py b/01 testik.py index d94b674..8c333e1 100644 --- a/01 testik.py +++ b/01 testik.py @@ -17,7 +17,8 @@ SOAP_NS = "http://schemas.xmlsoap.org/soap/envelope/" NS_STAV = "http://xmlns.gemsystem.cz/stavPojisteniB2B" # RC provided by you (can contain slash; we normalize before sending/saving) -RC = "280616/091" +RC = "7309208104" +# RC = "280616/091" K_DATU = date.today().isoformat() # MySQL (table already created as per previous DDL) diff --git a/03 Vyber.py b/03 Vyber.py new file mode 100644 index 0000000..87c758c --- /dev/null +++ b/03 Vyber.py @@ -0,0 +1,46 @@ +from functions import get_medicus_connection +from functions import get_mysql_connection +from functions import check_insurance +import time + +def prepare_processed_rcs(): + consql=get_mysql_connection() + cursql=consql.cursor() + + sql=""" + WITH ranked AS ( + SELECT + vr.*, + ROW_NUMBER() OVER ( + PARTITION BY rc + ORDER BY k_datu DESC, queried_at DESC + ) AS rn + FROM vzp_stav_pojisteni AS vr + ) + SELECT rc + FROM ranked + WHERE rn = 1 + """ + + cursql.execute(sql) + rows=cursql.fetchall() + print(f"Pocet jiz zpracovanych rodnych cisel v MYSQL MEDEVIO je {len(rows)}") + rc_set_vzp = {row["rc"] for row in rows} + return (rc_set_vzp) + +con=get_medicus_connection() +cur=con.cursor() +cur.execute("select rodcis, prijmeni, jmeno from kar where rodcis starting with '7'") + +rc_set_vzp=prepare_processed_rcs() + +rows=cur.fetchall() +print(f"Pocet vybranych radku z tabulky KAR je: {len(rows)}") + +for row in rows: + if row[0] in rc_set_vzp: + continue + else: + print(row[0], row[1],row[2]) + print(check_insurance(row[0])) + time.sleep(5) diff --git a/04 testik.py b/04 testik.py new file mode 100644 index 0000000..b2d20d6 --- /dev/null +++ b/04 testik.py @@ -0,0 +1,7 @@ +from functions import check_insurance + +if __name__ == "__main__": + rc = "7309208104" + res = check_insurance(rc) + print("=== RESULT ===") + print(res) \ No newline at end of file diff --git a/functions.py b/functions.py index 5d129aa..614717c 100644 --- a/functions.py +++ b/functions.py @@ -11,6 +11,48 @@ import requests from requests_pkcs12 import Pkcs12Adapter import pymysql from pymysql.cursors import DictCursor +import fdb + +MEDICUS_CFG = dict( + dsn=r"192.168.1.4:z:\medicus 3\data\medicus.fdb", + user="SYSDBA", + password="masterkey", + charset="win1250", +) + +def get_medicus_connection(): + """ + Attempt to create a Firebird connection to the Medicus database. + Returns: + fdb.Connection object on success + None on failure + """ + try: + return fdb.connect(**MEDICUS_CFG) + except fdb.fbcore.DatabaseError as e: + 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. + """ + try: + return pymysql.connect(**MYSQL_CFG) + except pymysql.MySQLError as e: + print(f"MySQL connection failed: {e}") + return None # ======== CONFIG (env overrides allowed) ======== PFX_PATH = os.getenv("VZP_PFX_PATH", r"mbcert.pfx")