-
Notifications
You must be signed in to change notification settings - Fork 332
/
Copy pathapp.py
142 lines (114 loc) · 6.84 KB
/
app.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
import tkinter as tk
import customtkinter as ctk
import threading
import time
from PIL import Image # Import the Image class
from bot import Bot
from utils import log_message
class App(ctk.CTk):
def __init__(self):
super().__init__()
self.title("TIKTOD V3")
self.geometry("800x600")
self.iconbitmap("./assets/logo.ico") # Add the icon
# Configure grid layout
self.grid_columnconfigure(1, weight=1)
self.grid_rowconfigure(0, weight=1)
# Create sidebar frame with widgets
self.sidebar_frame = ctk.CTkFrame(self, width=200, corner_radius=0, fg_color="gray20")
self.sidebar_frame.grid(row=0, column=0, rowspan=5, sticky="nsew")
self.sidebar_frame.grid_rowconfigure(9, weight=1)
custom_font = ctk.CTkFont(family="Helvetica", size=14, weight="bold")
self.logo_image_dark = ctk.CTkImage(light_image=Image.open("./assets/dark-logo.png"), size=(100, 100))
self.logo_image_light = ctk.CTkImage(light_image=Image.open("./assets/light-logo.png"), size=(100, 100))
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_entry = ctk.CTkEntry(self.sidebar_frame, width=180, font=custom_font)
self.link_entry.grid(row=2, column=0, padx=20, pady=5)
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)
# Create main frame with tab view for log and stats
self.main_frame = ctk.CTkFrame(self, corner_radius=0)
self.main_frame.grid(row=0, column=1, sticky="nsew")
self.main_frame.grid_rowconfigure(1, weight=1)
self.main_frame.grid_columnconfigure(0, weight=1)
self.tab_view = ctk.CTkTabview(self.main_frame)
self.tab_view.grid(row=0, column=0, padx=20, pady=10, sticky="nsew")
self.log_tab = self.tab_view.add("Log")
self.log_text = ctk.CTkTextbox(self.log_tab, height=300, width=600, font=custom_font)
self.log_text.pack(padx=20, pady=10, fill="both", expand=True)
self.stats_tab = self.tab_view.add("Stats")
self.stats_tab.grid_rowconfigure(0, weight=1)
self.stats_tab.grid_columnconfigure(0, weight=1)
self.stats_frame = ctk.CTkFrame(self.stats_tab)
self.stats_frame.grid(row=0, column=0, padx=20, pady=10, sticky="nsew")
self.stats_labels = {
"views": ctk.CTkLabel(self.stats_frame, text="Views Sent: 0", font=custom_font),
"hearts": ctk.CTkLabel(self.stats_frame, text="Hearts Sent: 0", font=custom_font),
"followers": ctk.CTkLabel(self.stats_frame, text="Followers Sent: 0", font=custom_font),
"shares": ctk.CTkLabel(self.stats_frame, text="Shares Sent: 0", font=custom_font),
"favorites": ctk.CTkLabel(self.stats_frame, text="Favorites Sent: 0", font=custom_font),
"elapsed_time": ctk.CTkLabel(self.stats_frame, text="Elapsed Time: 00:00:00", font=custom_font)
}
for i, label in enumerate(self.stats_labels.values()):
label.grid(row=i, column=0, padx=20, pady=5, sticky="w")
self.running = False # Add a flag to control the loop
self.mode_var = tk.StringVar(value="Views") # Initialize mode_var
self.bot = Bot(self, log_message)
self.elapsed_time = 0 # Initialize elapsed_time
self.views = 0 # Initialize views
self.hearts = 0 # Initialize hearts
self.followers = 0 # Initialize followers
self.shares = 0 # Initialize shares
self.favorites = 0 # Initialize favorites
self.theme_switch_var = tk.StringVar(value="dark")
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")
def switch_theme(self):
if self.theme_switch_var.get() == "dark":
ctk.set_appearance_mode("dark")
self.sidebar_frame.configure(fg_color="gray20")
self.logo_image_label.configure(image=self.logo_image_dark)
else:
ctk.set_appearance_mode("light")
self.sidebar_frame.configure(fg_color="white")
self.logo_image_label.configure(image=self.logo_image_light)
def setup_bot(self):
self.bot.setup_bot()
def start_bot(self):
auto = self.mode_var.get()
vidUrl = self.link_entry.get()
if auto in ["Views", "Hearts", "Followers", "Shares", "Favorites"]:
if not self.running:
self.start_time = time.time() - self.elapsed_time # Continue from the last elapsed time
self.log_text.delete(1.0, tk.END) # Clear the log area
log_message(self, "TIKTOD V3")
log_message(self, "Log:")
self.running = True # Set the flag to True
self.bot.running = True # Ensure the bot's running flag is also set to True
threading.Thread(target=self.update_stats_label).start() # Start the stats update thread
threading.Thread(target=self.bot.loop, args=(vidUrl, auto)).start()
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")
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):
while self.running:
time_elapsed = time.strftime('%H:%M:%S', time.gmtime(time.time() - self.start_time))
self.stats_labels["elapsed_time"].configure(text=f"Elapsed Time: {time_elapsed}")
self.stats_labels["views"].configure(text=f"Views Sent: {self.views}")
self.stats_labels["hearts"].configure(text=f"Hearts Sent: {self.hearts}")
self.stats_labels["followers"].configure(text=f"Followers Sent: {self.followers}")
self.stats_labels["shares"].configure(text=f"Shares Sent: {self.shares}")
self.stats_labels["favorites"].configure(text=f"Favorites Sent: {self.favorites}")
time.sleep(1)
if __name__ == "__main__":
app = App()
app.mainloop()