Skip to content

Commit

Permalink
full bot update
Browse files Browse the repository at this point in the history
  • Loading branch information
simonfarah committed Jul 21, 2023
1 parent f5ed1b1 commit f570cca
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 278 deletions.
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["ms-python.python"]
"recommendations": ["ms-python.python", "ms-python.black-formatter"]
}
12 changes: 5 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@
"editor.tabSize": 2,
"editor.detectIndentation": false,
"editor.insertSpaces": true,

// view
"editor.fontFamily": "Fira Code",
"editor.fontLigatures": true,
"editor.fontSize": 16,
"editor.fontSize": 18,
"editor.cursorStyle": "line",
"editor.cursorBlinking": "smooth",
"editor.cursorSmoothCaretAnimation": true,

// formating and linting
"editor.cursorSmoothCaretAnimation": "on",
// formating
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"[python]": {
"editor.defaultFormatter": "ms-python.python"
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "black"
"python.formatting.provider": "none"
}
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
## TikTok Bot

⚠️ Note: this is an old version of the script and has not been updated. You may face a lot of bugs and errors. A new stable version is in the making.

### Requirements

- Python 3.x
- Have [chromedriver](https://chromedriver.chromium.org/downloads) in the root directory (chromedriver version must be the same as your chrome browser version)
- Install the required modules
- Have [chrome](https://www.google.com/chrome/) installed
- Install the required modules (cd into the code directory and run this command)

pip install -r requirements.txt

### If you are not on Windows

If you are not using windows, open the `main.py` file using any text editor, go down to line 244 and follow the instruction

### How to use

1. Run the `main.py` file
2. Wait till the chromedriver opens, and solve the captcha
3. Minimize the chromedriver and continue working while the bot do its job
1. Run the `bot.py` file
2. Wait till the driver opens, and solve the captcha
3. The driver will be minimized and you can continue working while the bot do its job

### Disclaimer

Expand Down
209 changes: 209 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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()
Loading

0 comments on commit f570cca

Please sign in to comment.