Arkadaşlar merhaba sizlere iki sorum olacak, pythonla yazılan whatsapp toplu mesaj gönderme botum yavaş çalışıyor. Whatsapp web açılıyor mesaj giriyor fakat program enter tuşuna baya geç basıyor. time.sleep leri düşürdüm fakat yine aynı. İkinci sorum ise programım bu hatayı veriyor nasıl çözebilirim?
Belki çok basit bir sorun ama uzun zamandır python yazmıyorum o yüzden çoğu şeyi unuttum şimdiden teşekkür ederim.
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\furka\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "C:\Users\furka\PycharmProjects\whatsapp\main.py", line 108, in submitt
url = "https://web.whatsapp.com/send?phone={}&text={}&source&data&app_absent".format(numbers[i], msg)
IndexError: list index out of range
Kodum ektedir.
from tkinter import *
from tkinter import filedialog
import webbrowser
import time
import pyautogui as gui
import csv
from tkinter import messagebox
from io import BytesIO
import win32clipboard
from PIL import Image
import urllib.parse
global path
global success
global numentry
global imagepath
global image_success
global message
global instruct
imagepath = ""
path = ""
root = Tk()
root.title("Whatsapp Toplu Mesaj Gönderici")
root.configure(background="#075E54", height=900, width=1100)
def closeinstruct():
global instruct
instruct.place_forget()
def send_to_clipboard(clip_type, data):
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(clip_type, data)
win32clipboard.CloseClipboard()
def selectimage():
global imagepath
global image_success
root.imagename = filedialog.askopenfilename(initialdir="d:", title="select a file"
, filetype=(("JPEG Files", "*.jpg"), ("PNG files", "*.png")))
imagepath = root.imagename
if imagepath != "":
image_success = Label(root, text="Image received", fg="red", bg="#075E54", font="times 14")
image_success.place(relx=0.72, rely=0.72)
def selectfile():
global path
global success
root.filename = filedialog.askopenfilename(initialdir="d:", title="select a file"
, filetype=(("CSV Files", "*.csv"), ("all files", "*.*")))
path = root.filename
if path != "":
success = Label(root, text="File has been received", fg="red", bg="#075E54", font="times 14")
success.place(relx=0.47, rely=0.54)
def submitt():
global path
global imagepath
global numentry
global success
global image_success
global message
numbers = []
if path != "":
success.place_forget()
with open(path, 'rt') as f:
data = csv.reader(f)
for row in data:
for ele in row:
if len(ele) > 5:
if ele[0] == "+" or ele.isnumeric():
q = ele.strip()
q = q.rstrip()
numbers.append(q)
else:
st = numentry.get()
if st == "" or st == "Lütfen Ülke Kodu Girin...":
messagebox.showerror("Hata", "Lütfen Numara Listesi Girin..")
else:
numbers = [i.strip().rstrip() for i in st.split(",")]
try:
msg = urllib.parse.quote(message.get())
except Exception:
messagebox.showerror("Üzgünüz!", "Girilen Mesaj Türü Desteklenmiyor. Lütfen emoji vs. olmadan mesajınızı girin")
if msg == "" and imagepath == "":
messagebox.showerror("Hata", "Lütfen Mesajınızı Girin..")
else:
c = 1
if imagepath == "":
print(len(numbers))
for i in range(20):
if c == 1:
webbrowser.open("https://web.whatsapp.com")
time.sleep(12)
gui.keyDown('ctrl')
gui.press('w')
gui.keyUp('ctrl')
time.sleep(8)
c += 1
url = "https://web.whatsapp.com/send?phone={}&text={}&source&data&app_absent".format(numbers[i], msg)
webbrowser.open(url)
time.sleep(12)
gui.press('enter')
time.sleep(3)
gui.keyDown('ctrl')
gui.press('w')
gui.keyUp('ctrl')
time.sleep(1)
gui.press('enter')
if i == numbers[-1]:
time.sleep(2)
else:
time.sleep(8)
else:
image_success.place_forget()
filepath = imagepath
try:
image = Image.open(filepath)
output = BytesIO()
image.convert("RGB").save(output, "BMP")
data = output.getvalue()[14:]
output.close()
send_to_clipboard(win32clipboard.CF_DIB, data)
except Exception:
messagebox.showerror("sorry", "Not suitable attachment")
return
for i in range(20):
if c == 1:
webbrowser.open("https://web.whatsapp.com")
time.sleep(12)
gui.keyDown('ctrl')
gui.press('w')
gui.keyUp('ctrl')
time.sleep(8)
c += 1
url = "https://web.whatsapp.com/send?phone={}&text={}&source&data&app_absent".format(numbers[i], msg)
webbrowser.open(url)
time.sleep(12)
gui.keyDown('ctrl')
gui.press('v')
gui.keyUp('ctrl')
time.sleep(5)
gui.press('enter')
time.sleep(3)
gui.keyDown('ctrl')
gui.press('w')
gui.keyUp('ctrl')
time.sleep(1)
gui.press('enter')
if i == numbers[-1]:
time.sleep(2)
else:
time.sleep(8)
imagepath = ""
path = ""
numentry.delete(0, END)
message.delete(0, END)
canvas1 = Canvas(root, bg="orange")
canvas1.place(relx=0, rely=0, relwidth=1, relheight=0.2)
f1 = Frame(canvas1, bg="orange")
f1.place(relx=0.02, rely=0.02, relwidth=0.9, relheight=0.5)
head_text = Label(f1, text="Whatsapp Toplu Mesaj Gönderici v1.0", font="Helvetica 30 bold", fg="black", bg="orange")
head_text.place(relx=0.18, rely=0.03)
number = Label(root, text="Girmek istediğiniz numaraları (+90) ülke koduyla girin", font="Helvetica 16 bold", bg="#075E54", fg="snow")
number.place(relx=0.02, rely=0.22)
numentry = Entry(root, font="Helvetica 16")
numentry.place(relx=0.02, rely=0.30, relwidth=0.9, relheight=0.15)
insert_label = Label(root, text="Veya numara listesi açın", bg="#075E54", font="Helvetica 14 bold", fg="snow")
insert_label.place(relx=0.02, rely=0.48)
select = Button(root, text="Numara Listesi Seç", command=selectfile)
select.place(relx=0.05, rely=0.54, relwidth=0.4)
Message_label = Label(root, text="Mesajınızı Girin", font="Helvetica 16 bold", bg="#075E54", fg="snow")
Message_label.place(relx=0.02, rely=0.6)
attachment_label = Label(root, text="Resim Ekleyin:", font="Helvetica 16 bold", bg="#075E54", fg="snow")
attachment_label.place(relx=0.65, rely=0.6)
select_image = Button(root, text="Resim Seç" "", command=selectimage)
select_image.place(relx=0.65, rely=0.66, relwidth=0.3)
message = Entry(root, font="Helvetica 18")
message.place(relx=0.02, rely=0.65, relwidth=0.6, relheight=0.2)
submit = Button(root, text="Gönder", font="impact 20 bold", fg="white", bg="green", command=submitt)
submit.place(relx=0.3, rely=0.87, relwidth=0.4)
root.mainloop()