-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
86 lines (78 loc) · 2.93 KB
/
client.py
File metadata and controls
86 lines (78 loc) · 2.93 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
import requests
class Client:
def __init__(self):
self.end_point = "/join"
self.url = "http://127.0.0.1:5003"
# a token will be generated in server side and by using this token other automations are controlled (like sending messages and exit from the meeting)
self.token = None
self.headers = {"authentication": "jhf85yb#fl43d"}
self.loading = True
self.error = None
def join(self,webexUrl, name, email):
self.end_point = "/join"
body = {"name": name, "email": email,"url":webexUrl}
try:
response = requests.post(
self.url + self.end_point,
headers=self.headers,
json=body)
json_object = response.json()
if(json_object["success"]):
self.token = json_object["id"]
else:
self.error = json_object["error"]
self.loading = False
return json_object
except requests.exceptions.ConnectionError as e:
print("connection error")
print("Server is not started .Start the server and run again")
self.loading = False
self.error = str(e)
except Exception as e:
self.loading = False
self.error = str(e)
print(str(e))
def message(self, message):
self.loading = True
self.end_point = "/message"
body = {"id": self.token, "chat_message": message}
try:
response = requests.post(
self.url + self.end_point,
headers=self.headers,
json=body)
json_object = response.json()
self.loading = False
if(not json_object["success"]):
self.error = "Error occures try again"
except requests.exceptions.ConnectionError as e:
print("connection error")
print("Server is not started .Start the server and run again")
self.loading = False
self.error = str(e)
except Exception as e:
self.loading = False
self.error = str(e)
print(str(e))
def exit(self):
self.loading = True
self.end_point = "/exit"
body = {"id": self.token}
try:
response = requests.post(
self.url + self.end_point,
headers=self.headers,
json=body)
json_object = response.json()
self.loading = False
if(not json_object["success"]):
self.error = "Error occures try again"
except requests.exceptions.ConnectionError as e:
print("connection error")
print("Server is not started .Start the server and run again")
self.loading = False
self.error = str(e)
except Exception as e:
self.loading = False
self.error = str(e)
print(str(e))