-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ2_Client.py
177 lines (166 loc) · 5.9 KB
/
Q2_Client.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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import os
import platform
import requests
import time
import sys
import jsonspec
HOST = "localhost"
PORT = "1104"
CMD = token = ''
def __api__():
return "http://" + HOST + ":" + PORT + "/" + CMD
def printTickets(res):
number = res["tickets"].split('-')
i = 0
print("**************************************")
while i < int(number[1]):
block=res['block {}'.format(i)]
print('subject :'+block['subject'])
print('id :'+str(block['id']))
print('status :'+block['status'])
print('body :'+block['body'])
if block['answer']:
print('answer :'+block['answer'])
else:
print('answer :' + "")
print('date created :' + block['sendtime'])
time.sleep(0.2)
print("**************************************")
i=i+1
def clear():
if platform.system() == 'Windows':
os.system('cls')
else:
os.system('clear')
def control_panel_function():
print("""Give an Order:
1.Logout
2. Send a Ticket
3. Get Tickets as a Client
4. Close Ticket
5. Get Tickets as an Administrator
6. Respond to Ticket
7. Change a Ticket Status
8. Change Access to Administrator
9. Exit
""")
while True:
clear()
flag = 0
print("""WELCOME TO TICKET CLIENT
Please Choose What You Want To Do :
1. Login
2. Signup
3. Exit
""")
status = input()
if status == 1:
clear()
while True:
if flag == 1:
break
print("username : \n")
username = input()
print("password : \n")
password = input()
CMD = "login"
r = requests.post(__api__(), data={'username': username, 'password': password}).json()
print(r['message'] + '\n')
if r['code'] == '200':
clear()
api = r['api']
time.sleep(2)
else:
clear()
time.sleep(2)
break
while True:
clear()
control_panel_function()
order = input()
if order == 1:
clear()
CMD = "logout"
data = requests.post(__api__(), data={'username': username, 'password': password}).json()
print(data['message'] + '\n')
time.sleep(0.5)
flag = 1
break
if order == 2:
clear()
CMD = "sendticket"
subject = input("Enter Subject: ")
body = input("Enter Body: ")
data = requests.post(__api__(), data={'api': api, 'body': body, 'subject': subject}).json()
print(data['message'] + '\n')
time.sleep(0.5)
if order == 3:
clear()
CMD = "getticketcli"
data = requests.post(__api__(), params={'api': api}).json()
if data['code'] == '200':
printTickets(data)
else:
print(data['message']+'\n')
time.sleep(0.5)
if order == 4:
clear()
my_id = input("Ticket Id : ")
CMD = "closeticket"
data = requests.post(__api__(), data={'api': api, 'id': my_id}).json()
print(data['message']+'\n')
time.sleep(0.5)
if order == 5:
clear()
CMD = "getticketmod"
data = requests.post(__api__(), params={'api': api}).json()
if data['code'] == '200':
printTickets(data)
else:
print(data['message'] + '\n')
time.sleep(0.5)
if order == 6:
clear()
CMD = "restoticketmod"
answer = input("Enter Answer: ")
my_id = input("Enter Ticket ID:")
data = requests.post(__api__(), data={'api': api, 'id': my_id, 'answer': answer}).json()
print(data['message']+'\n')
time.sleep(0.5)
if order == 7:
clear()
CMD = "changestatus"
status = input("Status(Please enter open or closed or inprogress: ")
my_id = input("Enter Ticket id: ")
data = requests.post(__api__(), data={'api': api, 'id': my_id, 'status': status}).json()
print(data['message']+'\n')
time.sleep(0.5)
if order == 8:
clear()
CMD = "changeaccess"
dataBaseUser = input("Enter the username of the database to gain admin access: ")
dataBasePass = input("Enter the password of the database to gain admin access: ")
data = requests.post(__api__(), data={'api': api, 'dataBaseUser': dataBaseUser, 'dataBasePass': dataBasePass}).json()
print(data['message']+'\n')
time.sleep(0.5)
if order == 9:
sys.exit()
elif status == 2:
clear()
while True:
CMD = "signup"
username = input("Enter Username: ")
password = input("Enter Password: ")
clear()
data = requests.post(__api__(), data={'username': username, 'password': password}).json()
print(data['message']+'\n')
if str(data['code']) == "200":
time.sleep(1)
break
else:
time.sleep(2)
clear()
elif status == 3:
sys.exit()
else:
print("Please enter a valid number!\n")