forked from simonfarah/tiktok-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
209 lines (170 loc) · 7.79 KB
/
bot.py
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
from os import system
from time import sleep
from colorama import init, Fore
import undetected_chromedriver as uc
from selenium.common.exceptions import NoSuchElementException
init(autoreset=True)
class Bot:
def __init__(self):
system("cls || clear")
self.printBanner()
print(Fore.YELLOW + "[~] Loading driver, please wait...")
try:
self.driver = uc.Chrome()
except:
print(Fore.RED + "[!] No internet connection")
exit()
print(Fore.GREEN + "[+] Driver loaded succesfully")
print()
self.url = "https://zefoy.com"
self.captcha_xpath = "/html/body/div[5]/div[2]/form/div/div/div/div/button"
self.services = {
"followers": {
"title": "Followers",
"xpath": "/html/body/div[6]/div/div[2]/div/div/div[2]/div/button",
"status": None,
},
"hearts": {
"title": "Hearts",
"xpath": "/html/body/div[6]/div/div[2]/div/div/div[3]/div/button",
"status": None,
},
"comment_hearts": {
"title": "Comment Hearts",
"xpath": "/html/body/div[6]/div/div[2]/div/div/div[4]/div/button",
"status": None,
},
"views": {
"title": "Views",
"xpath": "/html/body/div[6]/div/div[2]/div/div/div[5]/div/button",
"status": None,
},
"shares": {
"title": "Shares",
"xpath": "/html/body/div[6]/div/div[2]/div/div/div[6]/div/button",
"status": None,
},
"favorites": {
"title": "Favorites",
"xpath": "/html/body/div[6]/div/div[2]/div/div/div[7]/div/button",
"status": None,
},
}
def start(self):
self.driver.get(self.url)
print(Fore.MAGENTA + "[!] In case of a 502 Bad Gateway error")
print(Fore.MAGENTA + "[!] please refresh the page")
print()
self.wait_for_xpath(self.captcha_xpath)
print(Fore.YELLOW + "[~] Please complete the captcha")
self.wait_for_xpath(self.services["followers"]["xpath"])
print(Fore.GREEN + "[+] Captcha completed sucessfully")
print()
self.driver.minimize_window()
self.check_services()
for index, service in enumerate(self.services):
title = self.services[service]["title"]
status = self.services[service]["status"]
print(Fore.BLUE + f"[{str(index + 1)}] {title}".ljust(20), status)
while True:
try:
choice = int(input(Fore.YELLOW + "[-] Choose an option : "))
except ValueError:
pass
if choice in [1, 2, 3, 4, 5, 6]:
break
if choice == 1: # followers
div = 7
self.driver.find_element(
"xpath", self.services["followers"]["xpath"]
).click()
elif choice == 2: # hearts
div = 8
self.driver.find_element("xpath", self.services["hearts"]["xpath"]).click()
elif choice == 3: # comment hearts
# div = 9
# self.driver.find_element(
# "xpath", self.services["comment_hearts"]["xpath"]
# ).click()
print()
print(Fore.RED + "[!] Comment heart option is not yet available")
exit()
elif choice == 4: # views
div = 10
self.driver.find_element("xpath", self.services["views"]["xpath"]).click()
elif choice == 5: # shares
div = 11
self.driver.find_element("xpath", self.services["shares"]["xpath"]).click()
elif choice == 6: # favorites
div = 12
self.driver.find_element(
"xpath", self.services["favorites"]["xpath"]
).click()
else:
exit()
print()
video_url = input(Fore.MAGENTA + "[-] Video URL : ")
print()
self.start_service(div, video_url)
def start_service(self, div, video_url):
url_input_xpath = f"/html/body/div[{div}]/div/form/div/input"
search_btn_xpath = f"/html/body/div[{div}]/div/form/div/div/button"
input = self.driver.find_element("xpath", url_input_xpath)
input.clear()
input.send_keys(video_url)
self.driver.find_element("xpath", search_btn_xpath).click()
sleep(3)
sleep_duration, can_proceed = self.check_submit(div)
if not can_proceed:
print(Fore.YELLOW + f"[~] Sleeping for {sleep_duration} seconds")
sleep(sleep_duration)
self.driver.find_element("xpath", search_btn_xpath).click()
send_btn_xpath = f"/html/body/div[{div}]/div/div/div[1]/div/form/button"
self.wait_for_xpath(send_btn_xpath)
self.driver.find_element("xpath", send_btn_xpath).click()
success_message_xpath = f"/html/body/div[{div}]/div/div/span[2]"
self.wait_for_xpath(success_message_xpath)
print(Fore.GREEN + "[+] Sent successfully")
self.start_service(div, video_url)
def check_submit(self, div):
remaining_time_xpath = f"/html/body/div[{div}]/div/div/span[1]"
try:
element = self.driver.find_element("xpath", remaining_time_xpath)
minutes = element.text.split("Please wait ")[1].split(" ")[0]
seconds = element.text.split("(s) ")[1].split(" ")[0]
sleep_duration = int(minutes) * 60 + int(seconds) + 5
return sleep_duration, False
except:
return None, True
def check_services(self):
for service in self.services:
xpath = self.services[service]["xpath"]
element = self.driver.find_element("xpath", xpath)
if element.is_enabled():
self.services[service]["status"] = Fore.GREEN + "[WORKING]"
else:
self.services[service]["status"] = Fore.RED + "[OFFLINE]"
def wait_for_xpath(self, xpath):
while True:
try:
_ = self.driver.find_element("xpath", xpath)
return True
except NoSuchElementException:
pass
def printBanner(self):
print(
"""
████████╗██╗██╗░░██╗████████╗░█████╗░██╗░░██╗ ██████╗░░█████╗░████████╗
╚══██╔══╝██║██║░██╔╝╚══██╔══╝██╔══██╗██║░██╔╝ ██╔══██╗██╔══██╗╚══██╔══╝
░░░██║░░░██║█████═╝░░░░██║░░░██║░░██║█████═╝░ ██████╦╝██║░░██║░░░██║░░░
░░░██║░░░██║██╔═██╗░░░░██║░░░██║░░██║██╔═██╗░ ██╔══██╗██║░░██║░░░██║░░░
░░░██║░░░██║██║░╚██╗░░░██║░░░╚█████╔╝██║░╚██╗ ██████╦╝╚█████╔╝░░░██║░░░
░░░╚═╝░░░╚═╝╚═╝░░╚═╝░░░╚═╝░░░░╚════╝░╚═╝░░╚═╝ ╚═════╝░░╚════╝░░░░╚═╝░░░
Made by : Simon Farah
Github : https://github.com/simonfarah/tiktok-bot
------------------------------------------------------------------------
"""
)
if __name__ == "__main__":
bot = Bot()
bot.start()