Skip to content

Commit

Permalink
Merge pull request #203 from kangoka/feat/amount-input
Browse files Browse the repository at this point in the history
feat: add amount input, disable fields when running, and update default option menu
  • Loading branch information
kangoka authored Jan 24, 2025
2 parents 830896b + 98fc801 commit 24b32b8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
35 changes: 28 additions & 7 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ def __init__(self):
self.logo_image_label = ctk.CTkLabel(self.sidebar_frame, image=self.logo_image_dark, text="")
self.logo_image_label.grid(row=0, column=0, padx=20, pady=(20, 20))

self.link_label = ctk.CTkLabel(self.sidebar_frame, text="TikTok video URL:", font=custom_font)
self.link_label.grid(row=1, column=0, padx=20, pady=10)
self.link_label = ctk.CTkLabel(self.sidebar_frame, text="TikTok video URL:", font=custom_font, anchor="w") # Added anchor="w"
self.link_label.grid(row=1, column=0, padx=20, pady=1, sticky="w") # Added sticky="w"
self.link_entry = ctk.CTkEntry(self.sidebar_frame, width=180, font=custom_font)
self.link_entry.grid(row=2, column=0, padx=20, pady=5)
self.link_entry.grid(row=2, column=0, padx=20, pady=1)

self.amount_label = ctk.CTkLabel(self.sidebar_frame, text="Amount:", font=custom_font, anchor="w") # New label
self.amount_label.grid(row=3, column=0, padx=20, pady=1, sticky="w") # New label grid
self.amount_entry = ctk.CTkEntry(self.sidebar_frame, width=180, font=custom_font) # New entry
self.amount_entry.grid(row=4, column=0, padx=20, pady=1) # New entry grid

self.start_button = ctk.CTkButton(self.sidebar_frame, text="Setup", command=lambda: threading.Thread(target=self.setup_bot).start(), font=custom_font)
self.start_button.grid(row=3, column=0, padx=20, pady=20)
self.start_button.grid(row=6, column=0, padx=20, pady=20) # Adjusted row to move the button lower

# Create main frame with tab view for log and stats
self.main_frame = ctk.CTkFrame(self, corner_radius=0)
Expand Down Expand Up @@ -84,7 +89,7 @@ def __init__(self):
self.theme_switch = ctk.CTkSwitch(self.sidebar_frame, text="Dark Mode", variable=self.theme_switch_var, onvalue="dark", offvalue="light", command=self.switch_theme, font=custom_font)
self.theme_switch.grid(row=10, column=0, padx=20, pady=10, sticky="s")

self.version_label = ctk.CTkLabel(self, text="Version 1.0.0", fg_color="transparent")
self.version_label = ctk.CTkLabel(self, text="Version 1.1.0", fg_color="transparent")
self.version_label.grid(row=5, column=1, padx=20, pady=(10, 0), sticky="se")

self.github_link = ctk.CTkLabel(self, text="https://github.com/kangoka/tiktodv3", fg_color="transparent", cursor="hand2")
Expand All @@ -111,6 +116,12 @@ def setup_bot(self):
def start_bot(self):
auto = self.mode_var.get()
vidUrl = self.link_entry.get()

try:
amount = int(self.amount_entry.get()) # Get the amount entered and ensure it is a number
except ValueError:
log_message(self, "Amount must be a number")
return

if auto in ["Views", "Hearts", "Followers", "Shares", "Favorites"]:
if not self.running:
Expand All @@ -122,19 +133,29 @@ def start_bot(self):
self.running = True # Set the flag to True
self.bot.running = True # Ensure the bot's running flag is also set to True

self.link_entry.configure(state="disabled") # Disable the URL entry
self.amount_entry.configure(state="disabled") # Disable the amount entry
self.mode_menu.configure(state="disabled") # Disable the option menu

threading.Thread(target=self.update_stats_label).start() # Start the stats update thread

threading.Thread(target=self.bot.loop, args=(vidUrl, auto)).start()
threading.Thread(target=self.bot.loop, args=(vidUrl, auto, amount)).start() # Pass the amount to the bot loop

self.start_button.configure(text="Stop", command=self.stop_bot)
else:
log_message(self, f"{auto} is not a valid option. Please pick Views, Hearts, Followers, Shares, or Favorites")

def stop_bot(self):
log_message(self, "Stop button pressed")
log_message(self, "Bot stopped")

self.link_entry.configure(state="normal") # Enable the URL entry
self.amount_entry.configure(state="normal") # Enable the amount entry
self.mode_menu.configure(state="normal") # Enable the option menu

self.running = False # Set the flag to False
self.bot.running = False # Ensure the bot's running flag is also set to False
self.elapsed_time = time.time() - self.start_time # Save the elapsed time

self.start_button.configure(text="Start", command=self.start_bot)

def update_stats_label(self):
Expand Down
16 changes: 13 additions & 3 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, app, log_callback):
self.running = False

def setup_bot(self):
log_message(self.app, "Setting up bot...")
log_message(self.app, "Setting up the bot...")
# Automatically install the correct version of ChromeDriver
chromedriver_autoinstaller.install()

Expand All @@ -46,7 +46,7 @@ def setup_bot(self):

self.app.mode_label = ctk.CTkLabel(self.app.mode_frame, text="Select Mode:")
self.app.mode_label.grid(row=0, column=0, padx=20, pady=10)
self.app.mode_var = tk.StringVar(value="Views")
self.app.mode_var = tk.StringVar(value="----------")

available_modes = []
buttons = {
Expand Down Expand Up @@ -150,7 +150,7 @@ def increment_mode_count(self, mode):
self.app.favorites += increment
log_message(self.app, f"Favorites incremented by {increment}")

def loop(self, vidUrl, mode):
def loop(self, vidUrl, mode, amount):
data = {
"Followers": {
"MainButton": '//button[@class="btn btn-primary rounded-0 t-followers-button"]',
Expand Down Expand Up @@ -231,6 +231,16 @@ def loop(self, vidUrl, mode):
# Increment counts based on mode
self.increment_mode_count(mode)

# Check if the amount limit is reached
if (mode == "Views" and self.app.views >= amount) or \
(mode == "Hearts" and self.app.hearts >= amount) or \
(mode == "Followers" and self.app.followers >= amount) or \
(mode == "Shares" and self.app.shares >= amount) or \
(mode == "Favorites" and self.app.favorites >= amount):
log_message(self.app, f"{mode} limit reached: {amount}")
self.app.stop_bot()
break

time.sleep(wait_seconds)
except Exception as e:
log_message(self.app, f"Error in {mode} loop: {e}")
Expand Down

0 comments on commit 24b32b8

Please sign in to comment.