diff --git a/.idea/Insurance.iml b/.idea/Insurance.iml index 235ece6..099709f 100644 --- a/.idea/Insurance.iml +++ b/.idea/Insurance.iml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 15d64b0..28a0efa 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,8 +1,9 @@ - + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6213dc3..da793cc 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,14 +5,10 @@ - - - - - - - - + + + + \ No newline at end of file diff --git a/03 Vyber.py b/03 Vyber.py index 87c758c..43c7a1a 100644 --- a/03 Vyber.py +++ b/03 Vyber.py @@ -1,7 +1,7 @@ from functions import get_medicus_connection from functions import get_mysql_connection from functions import check_insurance -import time +import time, random def prepare_processed_rcs(): consql=get_mysql_connection() @@ -43,4 +43,4 @@ for row in rows: else: print(row[0], row[1],row[2]) print(check_insurance(row[0])) - time.sleep(5) + time.sleep(random.uniform(1, 5)) diff --git a/functions.py b/functions.py index d250519..27eb0ad 100644 --- a/functions.py +++ b/functions.py @@ -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)