-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
148 lines (114 loc) · 4.14 KB
/
gui.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
143
144
145
146
147
148
import tkinter as tk
from tkinter import *
from tkinter import messagebox
import tkinter.ttk as ttk
from tkinter.filedialog import askopenfile, askopenfilename
from gsmmodem.modem import GsmModem
from progressbar import ProgressBar
import pandas as pd
import serial.tools.list_ports
import logging
from tqdm import *
from multiprocessing import Process
import smsCommands
import config
import testingNumbers
window = tk.Tk()
window.title("Khao Dosa Messaging Application")
window.geometry('800x800')
fileLoaded = 0
def main():
serialPortsList = detectSerialPorts()
initializeModem()
constructGui()
def detectSerialPorts():
serialPortsList = (list(serial.tools.list_ports.comports()))
if(len(serialPortsList) >= 1):
print("Serial Port detected. Confirm if Modem")
print(serialPortsList)
return serialPortsList
else:
print("\nNo Modem detected! Program exiting!\n")
messagebox.showerror(
"No Modem!", "No Modem detected! Program exiting. Check if modem is connected and showing in device manager!")
exit()
def createLabel():
lbl = tk.Label(window, text="Built by @Talal916",
font=("Arial Bold", 14))
lbl.grid(column=0, row=0)
def fileButtonClicked():
print("Adding Customers")
customerFileLocation = askopenfilename()
print(customerFileLocation)
global customerFileData
customerFileData = 0
customerFileData = pd.read_excel(
customerFileLocation, "Sheet1", usecols=["Name", "Mobile"])
print(customerFileData)
def initializeModem():
print('Initializing modem...')
global modem
modem = GsmModem(config.PORT, config.BAUDRATE,
smsReceivedCallbackFunc=smsCommands.handleSms)
# logging.basicConfig(format='%(levelname)s: %(message)s',
# level=logging.DEBUG)
modem.connect(config.PIN)
print("Modem IMEI: ", modem.imei)
testMessageRequest()
def testMessageRequest():
if(messagebox.askyesno("Send test message?", "Would you like to send a test sms message?")):
try:
smsCommands.testSms(modem)
except:
print("Failed to send test message. Check modem")
def constructGui():
print("Constructing GUI")
createLabel()
createButtons()
createMessageField()
window.mainloop()
def createMessageField():
global message
message = tk.Text(window, width=75, height=30)
message.grid(column=1, row=10)
def createButtons():
customerFileBtn = tk.Button(
window, text="Select customer file", command=fileButtonClicked)
customerFileBtn.grid(column=0, row=5)
sendMessageBtn = tk.Button(
window, text="Send Message", command=sendMessageButtonClicked)
sendMessageBtn.grid(column=0, row=6)
# cancelBtn = tk.Button(window, text="Cancel Send",
# command=cancelButtonClicked)
# def cancelButtonClicked():
def sendMessageButtonClicked():
if (askConfirmation()):
print("Calling message sender function")
callMessageSender(message.get('1.0', END))
else:
print("Message not sent, user declined")
def callMessageSender(messageText):
with tqdm(total=len(list(customerFileData.iterrows()))) as pbar:
for index, row in customerFileData.iterrows():
convertedNumber = "+92"+str(row['Mobile'])
personalizedMessage = messageText.replace("NAME", row['Name'])
print("Sending message: \n"+personalizedMessage +
"\n to: "+convertedNumber)
smsCommands.sendSms(modem, convertedNumber, personalizedMessage)
pbar.update(1)
def reinitializeModem():
try:
print('Reinitializing modem...')
global modem
modem = GsmModem(config.PORT, config.BAUDRATE,
smsReceivedCallbackFunc=smsCommands.handleSms)
modem.connect(config.PIN)
print("Modem IMEI: ", modem.imei)
except:
print("Failed to reinitialize modem")
def askConfirmation():
res = messagebox.askyesnocancel(
"Are you sure?", "Are you sure want to send this message to all your customers?")
return res
if __name__ == '__main__':
main()