-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonTerminalMessenger.py
More file actions
162 lines (119 loc) · 3.68 KB
/
PythonTerminalMessenger.py
File metadata and controls
162 lines (119 loc) · 3.68 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
try:
import keyboard
from playsound import playsound
import os
from twilio.rest import Client
import pyttsx3
import threading
except OSError:
print('you done goofed')
print('For this to work, I need to install some libaries')
choice = input('Proceed to install libaries? y or n ')
if choice == 'y':
os.system('pip install keyboard')
os.system('pip install playsound')
os.system('pip install twilio')
os.system('pip install pyttsx3')
class Communicator:
def __init__(self, message, account_sid, auth_token, recipient, sender):
self.message = message
self.account_sid = account_sid
self.auth_token = auth_token
self.sender = sender
self.recipient = recipient
def display_data(self):
print(self.recipient)
print(self.message)
def confirmation(self):
engine = pyttsx3.init()
engine.say("Your message reads")
engine.say(self.message)
engine.runAndWait()
proceed = input('Do you want to send this message? y or n ')
if proceed == "y":
self.send_message()
else:
pass
def send_message(self):
client = Client(self.account_sid, self.auth_token)
message = client.messages.create(body=self.message,from_=self.sender,to=self.recipient)
if message:
print('message sent successfully!')
playsound('successsend.mp3')
else:
print('something happened!')
playsound('error.mp3')
class ThreadListener:
def __init__(self):
self.running = True
def keyListener(self):
while self.running:
if keyboard.is_pressed('1'):
playsound('DTMFTones/dtmf-1.mp3')
elif keyboard.is_pressed('2'):
playsound('DTMFTones/dtmf-2.mp3')
elif keyboard.is_pressed('3'):
playsound('DTMFTones/dtmf-3.mp3')
elif keyboard.is_pressed('4'):
playsound('DTMFTones/dtmf-4.mp3')
elif keyboard.is_pressed('5'):
playsound('DTMFTones/dtmf-5.mp3')
elif keyboard.is_pressed('6'):
playsound('DTMFTones/dtmf-6.mp3')
elif keyboard.is_pressed('7'):
playsound('DTMFTones/dtmf-7.mp3')
elif keyboard.is_pressed('8'):
playsound('DTMFTones/dtmf-8.mp3')
elif keyboard.is_pressed('9'):
playsound('DTMFTones/dtmf-9.mp3')
elif keyboard.is_pressed('0'):
playsound('DTMFTones/dtmf-0.mp3')
elif keyboard.is_pressed('+'):
playsound('DTMFTones/dtmf-hash.mp3')
elif keyboard.is_pressed('esc'):
break
return False
def toneSound(self):
while self.running:
playsound('dialtone.mp3')
return False
def terminate(self):
self.running = False
def main():
dialer = ThreadListener()
# Create threads to add tone dialer sound effect
thread = threading.Thread(target=dialer.keyListener)
toneDialThread = threading.Thread(target=dialer.toneSound)
checked = 0
comm_constants = []
while True:
if checked == 0:
print('communicator opening up')
print('Please provide these details')
account_sid = input('Insert your account id: ')
auth_token = input('insert your auth token: ')
phone_state = input('Do you wish to turn the phone on? y or n: ')
if phone_state == "y":
thread.start()
toneDialThread.start()
sender = input('Please input senders number: ')
recipient = input('Enter the number you wish to send to: ')
dialer.terminate()
comm_constants.append(account_sid)
comm_constants.append(auth_token)
comm_constants.append(recipient)
comm_constants.append(sender)
checked = 1
else:
message = input('Write your message: ')
comm = Communicator(message, comm_constants[0], comm_constants[1], comm_constants[2], comm_constants[3])
comm.display_data()
## Read message to user
comm.confirmation()
confirm = input('Send another message to the same recipient? y or n')
if confirm == "y":
pass
else:
break
if __name__ == "__main__":
main()