-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.pyw
193 lines (163 loc) · 12.3 KB
/
main.pyw
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
import os
import re
import time
import base64
import requests
import threading
import customtkinter
from fake_useragent import UserAgent
from PIL import Image, UnidentifiedImageError
from tkinter.filedialog import askopenfilename
# TODO: fix this
icon = """
AAABAAEAMDAAAAEACACoDgAAFgAAACgAAAAwAAAAYAAAAAEACAAAAAAAAAkAAMMOAADDDgAAAAEAAAABAAAVAP8AHgr/AC0b/wAgDP8AFQH/ABYC/wAoFf8AIA3/AI2D/wDc2f8Awr3/AEs7/wBVRv8AzMj/AKWd/wAiD/8AKhf/AMfD/wD+/v8A////ANvY/wAzIf8A0s//AO3s/wA6Kf8AGAT/AGNV/wDi4P8Avbj/AIJ3/wD7+/8A2db/ACYT/wAXA/8A5eP/APz8/wCbk/8AGgb/AFdI/wDv7v8A9vb/AG5h/wDz8v8A9PT/AGVY/wBURf8A6ej/AP39/wAZBf8AiH7/APf3/wDh3/8APy7/ADgn/wDSzv8AKxn/ALSu/wDPy/8ANSP/ACkW/wDFwP8A19T/AD0s/wC1r/8AIQ7/AKqj/wDj4f8ASTn/AOjn/wCspf8Ai4H/AF1P/wBpXP8A8vH/AIR5/wBeUP8A8O//AG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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
"""
def write_to_terminal(text):
terminal.configure(state="normal")
terminal.insert("end", f"{text}\n")
terminal.configure(state="disabled")
def check_requisite(url, image):
if not re.fullmatch(r"^https://[a-zA-Z0-9-_]+\.straw\.page$", url):
preview_label.configure(image=None, text="Please enter a valid url!")
return False
if image == "":
preview_label.configure(image=None, text="Please select an image!")
return False
return True
def get_cookies(url):
ua = UserAgent()
headers = {"user-agent": ua.random}
write_to_terminal("[STATUS] Acquiring cookies...")
response = requests.get(url, headers=headers)
write_to_terminal("[SUCCESS] Cookies successfully get")
return response.cookies.get_dict()
def send(url, image):
url = url.get().rstrip('/')
image = image.get()
if not check_requisite(url, image):
return
API = url + "/gimmicks/canvas"
with open(image, "rb") as f:
im_bytes = base64.b64encode(f.read())
im_b64 = im_bytes.decode("utf-8")
payload = {"image": im_b64,
"ret": "true"}
headers = {
"Accept": "*/*",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
}
response = requests.post(API, headers=headers, cookies=get_cookies(url), data=payload)
if response.status_code == 200: # The api sends nothing on text for some reason, so this is the only way ( at least I think :p )
print(response.text)
write_to_terminal("[SUCCESS] Image successfully sent")
else:
write_to_terminal(f"[ERROR]: {response.text}")
write_to_terminal("\n")
write_to_terminal("Press any key to quit terminal :)")
cache = terminal.get("0.0", "end")
terminal.configure(state="normal")
while terminal.get("0.0", "end") == cache:
time.sleep(0.1)
terminal.delete("0.0", "end")
terminal.configure(state="disabled")
terminal.place_forget()
def parallel(url, image):
terminal.place(x=290, y=0)
threading.Thread(target=send, args=(url, image)).start()
def select_image():
path = askopenfilename(initialdir=os.getcwd(),
title="Select an image file")
if path != "":
input_image_path.set(path)
try:
img = Image.open(input_image_path.get())
if not img.is_animated:
preview_image = customtkinter.CTkImage(dark_image=img,size=(350, 350))
preview_label.configure(image=preview_image, text="")
else:
preview_image = customtkinter.CTkImage(dark_image=img,size=(350, 350))
preview_label.configure(image=preview_image, text="GIF is bad on tkinter, pretend it works :)")
except UnidentifiedImageError:
preview_label.configure(text="Nice choice :p")
# Create icon file and set it as icon then delete it, for simplistic
icondata = base64.b64decode(icon)
tempFile = "icon.ico"
with open(tempFile, "wb") as f:
f.write(icondata)
window = customtkinter.CTk()
window.geometry("640x350")
window.title("straw.page Image sender")
window.iconbitmap("icon.ico")
window.resizable(False, False)
customtkinter.set_appearance_mode("dark")
os.remove("icon.ico")
input_url = customtkinter.StringVar()
input_image_path = customtkinter.StringVar()
selection_frame = customtkinter.CTkFrame(master=window, fg_color="#141414")
inner_frame1 = customtkinter.CTkFrame(master=selection_frame, fg_color="transparent")
inner_frame2 = customtkinter.CTkFrame(master=selection_frame, fg_color="transparent")
inner_frame3 = customtkinter.CTkFrame(master=selection_frame, fg_color="transparent")
url_entry_label = customtkinter.CTkLabel(master=inner_frame1,
text="1. Enter straw.page URL",
font=("calibri", 18, "bold"),
)
url_entry_label.pack(pady=10)
url_entry = customtkinter.CTkEntry(master=inner_frame1,
font=("consolas", 14),
textvariable=input_url,
corner_radius=0,
border_width=1,
height=40,
)
url_entry.pack(fill='x')
# ~copied~ inspired by https://www.youtube.com/watch?v=u8Em9OQJXaI
select_image_button_label = customtkinter.CTkLabel(master=inner_frame2,
text="2. Select an image",
font=("calibri", 18, "bold"),
)
select_image_button_label.pack(pady=10)
select_image_button = customtkinter.CTkButton(master=inner_frame2,
text="S E L E C T",
text_color="#ffcc66",
fg_color="#141414",
command=select_image,
height=40,
corner_radius=0
)
select_image_button.pack(fill='x')
select_image_button.bind("<Enter>", lambda event: select_image_button.configure(text_color="#141414", fg_color="#ffcc66"))
select_image_button.bind("<Leave>", lambda event: select_image_button.configure(text_color="#ffcc66", fg_color="#141414"))
send_button_label = customtkinter.CTkLabel(master=inner_frame3,
text="3. Profit",
font=("calibri", 18, "bold"),
)
send_button_label.pack(pady=10)
send_button = customtkinter.CTkButton(master=inner_frame3,
height=40,
text="S E N D",
text_color="#25dae9",
fg_color="#141414",
corner_radius=0,
command=lambda: parallel(input_url, input_image_path),
)
send_button.pack(fill='x')
send_button.bind("<Enter>", lambda event: send_button.configure(text_color="#141414", fg_color="#25dae9"))
send_button.bind("<Leave>", lambda event: send_button.configure(text_color="#25dae9", fg_color="#141414"))
inner_frame1.pack(expand=True, fill="both")
inner_frame2.pack(expand=True, fill="both")
inner_frame3.pack(expand=True, fill="both")
selection_frame.pack(side="left", fill="both", expand=True)
preview_label = customtkinter.CTkLabel(master=window,
text="Image preview...",
font=("consolas", 12),
width=350,
height=350,
)
preview_label.pack(side="left")
terminal = customtkinter.CTkTextbox(master=window,
width=350,
height=350,
font=("consolas", 14),
state="disabled",
)
window.mainloop()