-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorrectt code.txt
46 lines (42 loc) · 1.67 KB
/
correctt code.txt
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
import pywhatkit
import time
import openpyxl
import random
def send_whatsapp_message(phone_number, message_text, image_path):
try:
# print("Please log in to WhatsApp Web and keep it open.")
time.sleep(5)
pywhatkit.sendwhats_image(phone_number, image_path, message_text)
print(f"Message and image sent to {phone_number}.")
except Exception as e:
print(f"Error sending message and image to {phone_number}: {e}")
def read_numbers_from_excel(excel_file_path):
try:
workbook = openpyxl.load_workbook(excel_file_path)
worksheet = workbook.active
phone_numbers = []
for row in worksheet.iter_rows(min_row=1):
phone_number = row[0].value
phone_numbers.append(str(int(phone_number)))
return phone_numbers
except Exception as e:
print(f"Error reading phone numbers from Excel file: {e}")
return []
# Main program
if __name__ == "__main__":
excel_file_path = "original.xlsx"
message_text = "Final testing"
image_path = "image.jpg"
phone_numbers = read_numbers_from_excel(excel_file_path)
print(phone_numbers)
# phone_numbers = ["9344776097", "7639262994"]
if phone_numbers:
for phone_number in phone_numbers:
if len(phone_number) >= 10 and phone_number.isdigit():
delay = random.randint(5, 12)
time.sleep(delay)
send_whatsapp_message("+91" + phone_number, message_text, image_path)
else:
print(f"Skipping invalid phone number: {phone_number}")
else:
print("No phone numbers found in the Excel file.")