-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_message_on_whatsapp.py
109 lines (92 loc) · 3.87 KB
/
send_message_on_whatsapp.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
#https://realpython.com/pysimplegui-python/ -->tutorial
from Send_message_script import Send_message_script
import PySimpleGUI as sg
import os.path
from Send_message_script import Send_message_script
import traceback
import keyboard
#TODO check input != {}
def main():
# First the window layout in 2 columns
file_list_column = [
[
sg.Text('''The CSV file must have ; as separator
the first line with name column
the phone nummber column called 'Number'!'''),
],
[
sg.Text("CSV File:"),
sg.In(size=(25, 1), enable_events=True, key="-FILE-"),
sg.FileBrowse(file_types=(("CSV files", "*.csv"),))
],
[
sg.Listbox(
values=[], enable_events=True, size=(40, 20), key="-VARIABLE LIST-"
)
],
]
# For now will only show the name of the file that was chosen
message_column = [
[sg.Text('''Write a message. If you want to insert a variable from the column that
is in the csv select the name from the list on left.
[Note - you can't use {} if you want to delete a variable you must delete {VariableName}]''')],
[sg.Multiline(size=(40, 20), key="-MULTILINE-")],
]
# ----- Full layout -----
layout = [
[
sg.Column(file_list_column),
sg.VSeperator(),
sg.Column(message_column),
],
[sg.Button('START')],
[sg.Text('''Start to send message.
In order to avoid error open a browser tab and don\'t close it.''', key='-SENDING-',visible=False)],
[sg.Text('Finished sending message', key='-FINISHED-', visible=False)]
]
window = sg.Window("Send message on whatsapp", layout)
# Run the Event Loop
while True:
event, values = window.read()
if event == "Exit" or event == sg.WIN_CLOSED:
break
# Folder name was filled in, make a list of files in the folder
if event == "-FILE-":
script = None
window['-MULTILINE-'].update('')
window["-VARIABLE LIST-"].update([])
window['-SENDING-'].Update(visible=False)
window['-FINISHED-'].Update(visible=False)
file = values["-FILE-"]
try:
#column_list
script = Send_message_script(file)
cnames = script.get_column_name()
except Exception as e:
tb = traceback.format_exc()
sg.Print(f'An error happened. Here is the info:', e, tb)
sg.popup_error(f'AN EXCEPTION OCCURRED!', e, tb)
cnames = []
window["-VARIABLE LIST-"].update(cnames)
elif event == "-VARIABLE LIST-": # A file was chosen from the listbox
text = window['-MULTILINE-']
text.update(text.get()[:-1]+ '{'+ values['-VARIABLE LIST-'][0] + '}')
elif event == "START":
if script is not None:
script.set_msg_string(window['-MULTILINE-'].get())
'''window.disable()
window['-SENDING-'].Update(visible=True)'''
window.close()
error_list = script.start_to_send()
print('\n'.join([i for i in error_list]
))
'''window['-SENDING-'].Update(visible=False
)
window['-FINISHED-'].Update(visible=True)
window.enable()
if len(error_list) != 0:
sg.popup_error(f'Message error list', '\n'.join([i for i in error_list[1:]]))'''
sg.popup(f'Message error list', '\n'.join([i for i in error_list[:]]),)
#window.close()
if __name__ == '__main__':
main()