-
Notifications
You must be signed in to change notification settings - Fork 0
/
sender.py
49 lines (44 loc) · 1.36 KB
/
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
40
41
42
43
44
45
46
47
48
49
import requests
# response = requests.get(
# 'http://127.0.0.1:5000/status'
# )
# print(response)
# print(response.status_code)
# print(response.headers)
# print(response.text)
# print(response.json()['name'])
sig = 0
name = input('Input your name: ')
while True:
if sig == 0:
username = input('Input your username: ')
response = requests.post(
'http://127.0.0.1:5000/send',
json={'name': name, 'username': username, 'text': '','status': 'login'}
)
data = response.json()
if data['status'] == 'Ok':
break
else:
sig = 1
else:
username = input('That username was used: Input your username again: ')
response = requests.post(
'http://127.0.0.1:5000/send',
json={'name': name, 'username': username, 'text': '', 'status': 'login'}
)
data = response.json()
if data['status'] == 'Ok':
break
while True:
text = input('Input your text:')
if text == "/logout":
response = requests.post(
'http://127.0.0.1:5000/send',
json={'name': name, 'username': username, 'text': text, 'status': 'logout'}
)
exit()
response = requests.post(
'http://127.0.0.1:5000/send',
json={'name': name, 'username': username, 'text': text, 'status': 'chat'}
)