File size: 10,055 Bytes
fca0b38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316

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()