Skip to content

Commit

Permalink
yeehaw
Browse files Browse the repository at this point in the history
  • Loading branch information
ziggoon committed Dec 9, 2023
1 parent 16285a7 commit f72aa82
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 18 deletions.
13 changes: 10 additions & 3 deletions python/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@
logger.addHandler(fh)
logger.addHandler(ch)

def run_bot(bot, event):
def run_bot(bot, event, collection_method):
event.wait()
bot.start(db)

match collection_method:
case "fyp":
bot.fyp(db)
case "default":
bot.start(db)
case default:
print("[-] invalid collection method")

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="tiktok-botz")
Expand Down Expand Up @@ -60,7 +67,7 @@ def run_bot(bot, event):
db.add_sessionid(bot.username, sessionid)
break
else:
t = threading.Thread(target=run_bot, args=(bot, input_event))
t = threading.Thread(target=run_bot, args=(bot, input_event, args.collection_method))
threads.append(t)

if len(threads) == 5 or i == len(bots) - 1:
Expand Down
79 changes: 64 additions & 15 deletions python/tiktok/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ def proxies() -> dict:

return wire_options

def create_data_dir():
dir_path = "data/html"
if not os.path.exists(dir_path):
os.makedirs(dir_path)
else:
pass


class AccountType(Enum):
LIKE = 0
Expand Down Expand Up @@ -64,14 +71,14 @@ def generate_account_type(self):

def setup_webdriver(self):
options = webdriver.ChromeOptions()
options.headless = True
options.headless = False
options.add_argument(f"user-agent={random.choice(USER_AGENTS)}")
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)

driver = webdriver.Chrome(
ChromeDriverManager().install(), options=options, seleniumwire_options=proxies()
ChromeDriverManager().install(), options=options #seleniumwire_options=proxies()
)

stealth(driver,
Expand Down Expand Up @@ -145,23 +152,12 @@ def start(self, db):
print("cookie not found")
return


dir_path = "data/html"
if not os.path.exists(dir_path):
os.makedirs(dir_path)
else:
pass
create_data_dir()

start_time = time.time()
db.logger.info(f"starting run on {self.username} @ {start_time}")
print(f"[!] starting run on {self.username} @ {start_time}")

#self.driver.get("https://bot.sannysoft.com/")
#sleep(5)
#self.driver.save_screenshot("images/sannysoft.png")
#sleep(1)


if self.status == False:
#self.type_ = self.generate_account_type()
db.update_status(self.username, True)
Expand Down Expand Up @@ -231,7 +227,7 @@ def start(self, db):
sleep(5)
try:
self.driver.find_element(By.TAG_NAME, "video").click()
except:
except ElementClickInterceptedException:
self.driver.refresh()
self.driver.find_element(By.TAG_NAME, "video").click()

Expand Down Expand Up @@ -267,3 +263,56 @@ def start(self, db):

else:
db.logger.error(f"[!] invalid user type! :: {self.type_}")

def fyp(self, db):
self.login()
if self.driver.get_cookie("sessionid") is not None:
db.logger.info(f"{self.username} logged into TikTok successfully")
print(f"[+] logged in with {self.username}")

else:
print("cookie not found")
return

create_data_dir()

start_time = time.time()
db.logger.info(f"starting run on {self.username} @ {start_time}")
print(f"[!] starting run on {self.username} @ {start_time}")


self.driver.get("https://www.tiktok.com/foryou")
for i in range(100):
duration = random.randint(30,50)
sleep(5)
try:
self.driver.find_element(By.TAG_NAME, "video").click()
except ElementClickInterceptedException:
self.driver.refresh()
self.driver.find_element(By.TAG_NAME, "video").click()

db.logger.info(f"{self.username} sleeping for {duration + 7}s")
time.sleep(duration)

author = self.driver.find_element(By.XPATH, "//span[contains(@data-e2e, 'browse-username')]").text
description = self.driver.find_element(By.XPATH, "//div[contains(@data-e2e, 'browse-video-desc')]").text
likes = self.driver.find_element(By.XPATH, "//strong[contains(@data-e2e, 'browse-like-count')]").text
comments = self.driver.find_element(By.XPATH, "//strong[contains(@data-e2e, 'browse-comment-count')]").text
bookmarks = self.driver.find_element(By.XPATH, "//strong[contains(@data-e2e, 'undefined-count')]").text
shares = self.driver.find_element(By.XPATH, "//strong[contains(@data-e2e, 'share-count')]").text
post_date = self.driver.find_element(By.XPATH, "//span[contains(@data-e2e, 'browser-nickname')]").text
video_sound = self.driver.find_element(By.XPATH, "//div[contains(@class, 'epjbyn3')]").text
video_url = self.driver.current_url

#print(f"Current video: {author}, {description}, Likes: {likes}, Comments: {comments}, Bookmarks: {bookmarks}, Shares: {shares}, Post Date: {post_date}")
video = videos.Video(author, description, likes, comments, bookmarks, shares, post_date, video_sound, video_url)
db.insert_fyp_video(self.username, video)

with open(f"data/html/{self.username}-{video_url.split('video/')[1]}.html", "w", encoding="utf-8") as f:
f.write(self.driver.page_source)

self.driver.find_element(By.XPATH, "/html/body/div[1]/div[2]/div[4]/div/div[1]/button[1]").click()
sleep(5)

self.scroll()
db.logger.info(f"[+] {self.username} scrolling on fyp")

0 comments on commit f72aa82

Please sign in to comment.