-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsender_functions.py
49 lines (45 loc) · 1.44 KB
/
sender_functions.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
import pandas as pd
import pywhatkit as pw
import time
from openpyxl import load_workbook
import keyboard as k
import random
# Format phone numbers
def format_phone(phone):
if len(phone) == 10 and phone[0] == '0':
phone = phone.replace('0', '996', 1)
return phone
elif len(phone) == 9:
phone = phone + '996'
return phone
for i in phone:
if i in '-() +;':
phone = phone.replace(i, '')
return '+' + phone
else:
return phone
phone = '+' + phone.replace('.0', '')
return phone
# Read the text for the mailout message
def read_txt_file(txtpath):
with open(txtpath, 'r', encoding='utf-8') as f:
text_msg = ''
for row in f:
text_msg += row
return text_msg
# Sender function with random wait times in execution
def send_msg(phone, msg):
sec = random.randint(40, 60)
phone = format_phone(phone)
pw.sendwhatmsg_instantly(phone, msg, wait_time=sec, close_time=random.randint(5, 10))
time.sleep(random.randint(10, 15))
k.press_and_release('ctrl+w')
# Log the operation in the mailout log
def logwriter(dftemp, logpath):
workbook = load_workbook(logpath)
writer = pd.ExcelWriter(logpath, engine='openpyxl')
writer.book = workbook
worksheet = workbook.active
dftemp = dftemp.transpose()
dftemp.to_excel(writer, startrow=worksheet.max_row, startcol=0, index = False, header= False)
writer.close()