mirror of
https://github.com/Sneed-Group/pypush-plus-plus
synced 2024-12-23 11:22:42 -06:00
create a simple interactive prompt
This commit is contained in:
parent
306bfd483f
commit
ef9fd77bcb
2 changed files with 38 additions and 1 deletions
2
apns.py
2
apns.py
|
@ -50,7 +50,7 @@ class IncomingQueue:
|
|||
with self.lock:
|
||||
self.queue.append(item)
|
||||
|
||||
def pop(self, index):
|
||||
def pop(self, index = -1):
|
||||
with self.lock:
|
||||
return self.queue.pop(index)
|
||||
|
||||
|
|
37
demo.py
37
demo.py
|
@ -108,7 +108,44 @@ with open("config.json", "w") as f:
|
|||
|
||||
im = imessage.iMessageUser(conn, user)
|
||||
|
||||
# Create a thread to take user input
|
||||
INPUT_QUEUE = apns.IncomingQueue()
|
||||
|
||||
def input_thread():
|
||||
while True:
|
||||
from prompt_toolkit import prompt
|
||||
|
||||
try:
|
||||
msg = prompt('>> ')
|
||||
except:
|
||||
msg = 'quit'
|
||||
INPUT_QUEUE.append(msg)
|
||||
|
||||
threading.Thread(target=input_thread, daemon=True).start()
|
||||
|
||||
|
||||
while True:
|
||||
msg = im.receive()
|
||||
if msg is not None:
|
||||
print(f"Got message {msg}")
|
||||
|
||||
if len(INPUT_QUEUE) > 0:
|
||||
msg = INPUT_QUEUE.pop()
|
||||
if msg == 'help' or msg == 'h':
|
||||
print('help (h): show this message')
|
||||
print('quit (q): quit')
|
||||
print('send (s) [recipiant] [message]: send a message')
|
||||
elif msg == 'quit' or msg == 'q':
|
||||
break
|
||||
elif msg.startswith('send') or msg.startswith('s'):
|
||||
msg = msg.split(' ')
|
||||
if len(msg) < 3:
|
||||
print('send [recipiant] [message]')
|
||||
else:
|
||||
imsg = imessage.iMessage()
|
||||
imsg.text = ' '.join(msg[2:])
|
||||
imsg.participants = [msg[1], user.handles[0]]
|
||||
imsg.sender = user.handles[0]
|
||||
|
||||
im.send(imsg)
|
||||
|
||||
|
|
Loading…
Reference in a new issue