-
Notifications
You must be signed in to change notification settings - Fork 0
/
sender.py
39 lines (29 loc) · 965 Bytes
/
sender.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
import atexit
import requests
import sys
url = sys.argv[1] if len(sys.argv) > 1 else 'http://127.0.0.1:5000/'
while True:
print('Enter username: ', end='')
username = input()
print('Enter password: ', end='')
password = input()
response = requests.post(url + 'login',
json={'username': username, 'password': password})
if response.status_code == 200:
break
else:
print('Error: ' + response.json().get('error'))
def exit_handler():
requests.post(url + 'logout',
json={'username': username, 'password': password})
atexit.register(exit_handler)
while True:
print('Text: ', end='')
text = input()
if len(text) == 0:
continue
response = requests.post(url + 'send',
json={'username': username, 'password': password, 'text': text})
if response.status_code == 200:
print('Message sent')
print()