import re with open('fotograf-de-scraper/backend/main.py', 'r') as f: content = f.read() old_code = """ try: wait_short = WebDriverWait(driver, 5) quick_link_el = wait_short.until(EC.presence_of_element_located((By.XPATH, SELECTORS["quick_login_url"]))) quick_link = quick_link_el.get_attribute("href") # Update DB codes_to_find[code].quick_login_url = quick_link del codes_to_find[code] links_found += 1 if links_found % 5 == 0: db.commit() except: logger.warning(f"Could not find quick login link for {code}")""" new_code = """ for attempt in range(3): try: wait_short = WebDriverWait(driver, 5) quick_link_el = wait_short.until(EC.visibility_of_element_located((By.XPATH, SELECTORS["quick_login_url"]))) quick_link = quick_link_el.get_attribute("href") # Update DB codes_to_find[code].quick_login_url = quick_link del codes_to_find[code] links_found += 1 if links_found % 5 == 0: db.commit() break except Exception as e: time.sleep(1) else: logger.warning(f"Could not find quick login link for {code}")""" if old_code in content: content = content.replace(old_code, new_code) with open('fotograf-de-scraper/backend/main.py', 'w') as f: f.write(content) print("Patched successfully") else: print("Old code not found")