-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzoho1.py
More file actions
173 lines (138 loc) · 6.98 KB
/
Copy pathzoho1.py
File metadata and controls
173 lines (138 loc) · 6.98 KB
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
import csv
import threading
import time
import random
import string
import pyautogui
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
def generate_random_email():
random_string = ''.join(random.choices(string.ascii_lowercase, k=15))
return f"{random_string}@gmail.com"
def generate_random_password():
return ''.join(random.choices(string.ascii_letters + string.digits, k=10))
def read_phone_numbers(file_path):
phone_numbers = []
with open(file_path, mode='r') as file:
csv_reader = csv.reader(file)
for row in csv_reader:
for cell in row:
if cell.strip().isdigit():
phone_numbers.append(cell.strip())
return phone_numbers
def setup_driver():
service = ChromeService(ChromeDriverManager().install())
options = webdriver.ChromeOptions()
proxy = "ke.smartproxy.com:45001:spd4l2uu3a:~00lDcWXuhopL1l0am"
# # Proxy configuration
# if proxy:
# proxy_parts = proxy.split(':')
# if len(proxy_parts) == 4: # Expected format: url:port:user:password
# proxy_host, proxy_port, proxy_user, proxy_password = proxy_parts
# proxy_str = '{hostname}:{port}'.format(hostname=proxy_host, port=proxy_port)
# options.add_argument('--proxy-server={}'.format(proxy_str))
# else:
# print("Invalid proxy format, skipping proxy setup.")
options.add_argument("--window-size=1400,820")
options.add_argument("--window-position=0,0")
driver = webdriver.Chrome(service=service, options=options)
return driver
def automate_login(phone_numbers):
driver = setup_driver()
try:
driver.get("https://www.zoho.com/")
start_cnt = 0
cnt = start_cnt
cnt_otp = 0
email = ''
true_flag = 0
while(1):
phone = phone_numbers[cnt]
cnt = cnt + 1
print(phone)
# Store the current tab
old_tab = driver.current_window_handle
driver.execute_script("window.open('');")
driver.switch_to.window(driver.window_handles[-1]) # Switch to the new tab
# Navigate to Zoho in the new tab
driver.get("https://www.zoho.com/")
if cnt != start_cnt+1:
username = email.split("@")[0]
xpath = f"//img[@alt='{username}']"
wait.until(EC.presence_of_element_located((By.XPATH, xpath))).click()
wait.until(EC.presence_of_element_located((By.LINK_TEXT, "Sign Out"))).click()
wait = WebDriverWait(driver, 20)
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, "zgh-signup"))).click()
email = generate_random_email()
wait.until(EC.presence_of_element_located((By.ID, "email"))).send_keys(email)
password = generate_random_password()
wait.until(EC.presence_of_element_located((By.ID, "password"))).send_keys(password)
if (cnt == start_cnt+1):
pyautogui.moveTo(360, 735, duration=1) # Optional duration to make it smooth
pyautogui.click()
time.sleep(0.5)
pyautogui.moveTo(560, 735, duration=0.5) # Optional duration to make it smooth
pyautogui.click()
time.sleep(1)
print("here")
driver.execute_script("document.getElementById('signupbtn').click()")
username = email.split("@")[0]
xpath = f"//img[@alt='{username}']"
wait.until(EC.presence_of_element_located((By.XPATH, xpath))).click()
wait.until(EC.presence_of_element_located((By.LINK_TEXT, "My Account"))).click()
button = wait.until(EC.presence_of_element_located((By.ID, "add_newnobackup")))
# driver.execute_script("arguments[0].scrollIntoView(true);", button)
# wait.until(EC.element_to_be_clickable((By.ID, "add_newnobackup"))).click()
driver.execute_script("arguments[0].click();", button)
max_time = 10
for i in range(max_time):
try:
wait.until(EC.presence_of_element_located((By.ID, "select_phonenumber_input"))).clear()
wait.until(EC.presence_of_element_located((By.ID, "select_phonenumber_input"))).send_keys(phone)
wait.until(EC.element_to_be_clickable((By.ID, "popup_mobile_action"))).click()
time.sleep(1)
back_button = wait.until(EC.presence_of_element_located((By.ID, "add_mobile_back")))
if back_button.is_displayed():
print(f"Phone number {phone} is correct. Repeating actions for remaining attempts.")
wait.until(EC.element_to_be_clickable((By.ID, "add_mobile_back"))).click()
# Repeat "add" and "back" for the remaining attempts
true_flag = 1
for j in range(max_time - i):
wait.until(EC.element_to_be_clickable((By.ID, "popup_mobile_action"))).click()
wait.until(EC.element_to_be_clickable((By.ID, "add_mobile_back"))).click()
break # Exit loop as task is complete
phone = phone_numbers[cnt]
cnt = cnt + 1
true_flag = 0
except Exception as e:
print(f"Error during automation for phone {phone}: {e}")
close_btn = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "div.close_btn[onclick='close_popupscreen()']"))
)
close_btn.click()
driver.switch_to.window(old_tab)
driver.close()
driver.switch_to.window(driver.window_handles[0])
finally:
cont = input("Can we continue: ").strip()
time.sleep(10)
driver.quit()
def main():
phone_csv_path = 'phone.csv'
# Read data from CSV files
phone_numbers = read_phone_numbers(phone_csv_path)
# Input the head number to remove from all phone numbers
head_number = input("Enter the head number to remove from each phone number (if present): ").strip()
phone_numbers = [phone[len(head_number):] if phone.startswith(head_number) else phone for phone in phone_numbers]
# Determine the minimum length between phone numbers and proxies
repeat_count = len(phone_numbers)
print(f"Repeating the automation {repeat_count} times")
automate_login(phone_numbers)
if __name__ == "__main__":
main()