from flask import Flask, request, jsonify import subprocess import logging from gemini import main # Set up logging logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) app = Flask(__name__) @app.route('/') def hello_world(): logger.info('Received request for root endpoint') return 'Cloud Run Python Script is Running!' # Modify the route to accept the 'user_input' as a URL parameter @app.route('/run-script', methods=['POST']) def run_script(): logger.info('Received request to /run-script endpoint') # Get the user_input from URL parameters or request body data = request.get_json() customer = data.get('customer') user = data.get('user') pwd = data.get('pwd') logger.info(f'Request Parameters - customer: {customer}, user: {user}') if not customer: logger.error('No customer parameter provided!') return jsonify({"error": "No customer parameter provided!"}), 400 try: logger.info(f'Running script with customer: {customer}, user: {user}') # Call the `main()` function from infiplex.py and pass the parameters main(customer, user, pwd) logger.info('Script ran successfully') return jsonify({ 'status': 'success', 'message': f'Processed input: {customer}' }) except Exception as e: logger.error(f'Error running script: {e}', exc_info=True) return jsonify({ 'status': 'error', 'message': str(e) }), 500 if __name__ == '__main__': logger.info('Starting Flask application') app.run(host='0.0.0.0', port=8080) # from selenium import webdriver # from selenium.webdriver.chrome.service import Service # from selenium.webdriver.chrome.options import Options # from webdriver_manager.chrome import ChromeDriverManager # from selenium.webdriver.common.by import By # from selenium.webdriver.common.keys import Keys # from selenium.webdriver.common.action_chains import ActionChains # from selenium.webdriver.support.ui import WebDriverWait # from selenium.webdriver.support import expected_conditions as EC # import time # import sys # chrome_options = Options() # # chrome_options.add_argument("--headless") # Uncomment to run headless # chrome_options.add_argument("--no-sandbox") # chrome_options.add_argument("--disable-dev-shm-usage") # chrome_options.add_argument("start-maximized") # service = Service() # driver = webdriver.Chrome(service=service, options=chrome_options) # wait = WebDriverWait(driver, 20) # driver.get("https://xindus-01.infiplex.com/admin/admin_login.php") # driver.maximize_window() # user_input = sys.argv[0] # # Step 3: Locate and fill the username field # username_field = driver.find_element(By.ID, 'uname') # Replace with the actual element's ID # username_field.send_keys('saptarshi@xindus.net') # # Step 4: Locate and fill the password field # password_field = driver.find_element(By.ID, 'password') # Replace with the actual element's ID # #password_field.send_keys('xindusAdmin95672!') # password_field.send_keys('2ZLcrwZu838QBnBYFz4bRK2h5Njt1l') # # Step 5: Locate and click the login button # login_button = driver.find_element(By.ID, 'submit') # Replace with the actual button's ID # login_button.click() # # Wait for login to complete # time.sleep(3) # print(f"Current URL after login: {driver.current_url}") # print(f"Page title after login: {driver.title}") # ###################################################### # driver.get("https://xindus-01.infiplex.com//admin/sitearea/siteareaadd.php") # # Wait for the page to load # time.sleep(3) # print(f"Current URL: {driver.current_url}") # print(f"Page title: {driver.title}") # # Check if we're on the right page by looking for the form # try: # # Wait for the element to be present # name_field = WebDriverWait(driver, 10).until( # EC.presence_of_element_located((By.ID, "sitearea_name")) # ) # except: # print("Element 'sitearea_name' not found. Let's check what's on the page...") # # Save page source for debugging # with open('/Users/prasanth/Desktop/debug_page.html', 'w') as f: # f.write(driver.page_source) # print("Page source saved to debug_page.html") # # Try to find any input fields to see what's available # input_fields = driver.find_elements(By.TAG_NAME, "input") # print(f"Found {len(input_fields)} input fields:") # for i, field in enumerate(input_fields[:10]): # Show first 10 # field_id = field.get_attribute("id") # field_name = field.get_attribute("name") # field_type = field.get_attribute("type") # print(f" {i+1}. ID: {field_id}, Name: {field_name}, Type: {field_type}") # driver.quit() # exit(1) # # Form filling logic (replace with your actual field names and values) # name_field.send_keys(user_input) # description_field = driver.find_element(By.ID, "base_folder") # description_field.send_keys(user_input) # description_field = driver.find_element(By.ID, "content_section_name") # description_field.send_keys(user_input) # rbutton = driver.find_element(By.ID, "_content_section_security_group_all_users_yes") # rbutton.click() # #time.sleep(2) # Adjust wait time as needed # # Navigate to the "Applications" tab # applications_tab = driver.find_element(By.LINK_TEXT, "Applications") # applications_tab.click() # # Select the specific radio button # rbutton = driver.find_element(By.ID, "install_app_yes_no_325") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_320") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_317") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_342") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_322") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_346") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_393") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_387") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_336") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_31") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_195") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_293") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_5") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_384") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_340") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_344") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_3") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_334") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_327") # rbutton.click() # rbutton = driver.find_element(By.ID, "install_app_yes_no_7") # rbutton.click() # #time.sleep(2) # Adjust wait time as needed # #save_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "submit"))) # save_buttons = driver.find_elements(By.ID, "submit") # save_button = save_buttons[1] # time.sleep(2) # if save_button.is_displayed(): # driver.execute_script("arguments[0].scrollIntoView();", save_button) # save_button.click() # else: # # Handle the case where the button is not visible # print("Save button is not visible!") # ############################################################ # driver.get("https://xindus-01.infiplex.com/admin/index.php") # links = driver.find_elements(By.TAG_NAME, "a") # # Loop through the links and click on the one with the matching display_name # for link in links: # href_value = link.get_attribute("href") # print(href_value) # if href_value and user_input in href_value: # Check if href_value is not None and contains user_input # link.click() # break # # Close the browser after some time (optional) # time.sleep(1) # #input("Form submitted. Press Enter to close the browser...") # try: # iframe = WebDriverWait(driver, 10).until( # EC.presence_of_element_located((By.TAG_NAME, 'iframe')) # ) # driver.switch_to.frame(iframe) # except Exception as e: # print(f"Could not find iframe: {e}") # # Debugging: print page source or take screenshot # with open('debug_page.html', 'w') as f: # f.write(driver.page_source) # print("Saved page source to debug_page.html") # driver.save_screenshot('debug_screenshot.png') # print("Saved screenshot to debug_screenshot.png") # link = WebDriverWait(driver, 10).until( # EC.presence_of_element_located((By.CSS_SELECTOR, "a[href*='product_upload']")) # ) # link.click() # time.sleep(1) # link=driver.find_element(By.PARTIAL_LINK_TEXT, "API") # link.click() # time.sleep(1) # link=driver.find_element(By.PARTIAL_LINK_TEXT, "Create New") # link.click() # time.sleep(1) # iframe = driver.find_element(By.XPATH, "//iframe[@src='admin_api_add_edit.php?aid=0']") # driver.switch_to.frame(iframe) # name_field = driver.find_element(By.ID, "reference_name") # name_field.send_keys("StoreAPI") # # Locate all checkboxes in the specific table cell # checkboxes = driver.find_elements(By.XPATH, "//td[@style='text-align:left;vertical-align:top;']//input[@type='checkbox']") # # Loop through all checkboxes and select them # for checkbox in checkboxes: # if not checkbox.is_selected(): # checkbox.click() # # driver.execute_script("parent.swcm_show_admin_page({page_id:'sitearea_26_510',page_path:'admin/sitearea/26/510/index.php',display_name:'"+user_input+" - Shop'})") # save_button = driver.find_element(By.ID, "submit") # save_button.click() # time.sleep(5) # Adjust wait time as needed # input("Press enter to quit the browser") # driver.quit()