-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathticket_viewer.py
More file actions
82 lines (59 loc) · 2.43 KB
/
ticket_viewer.py
File metadata and controls
82 lines (59 loc) · 2.43 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
# Name: Kat Kime
# Date: 8/1/2021
# Description: Allows users to access tickets for a given account number.
import requests
import Constants
import ticket_database
_AUTHORIZATION = Constants.AUTHORIZATION_KEY
_DOMAIN = Constants.DOMAIN
def get_tickets(authorization, domain) -> dict:
"""
Connects with the Zendesk API to receive tickets for a given account.
Args:
authorization: Zendesk authorization code
domain: Domain for the Zendesk company
Returns:
"""
tickets_url = f"https://{domain}.zendesk.com/api/v2/tickets.json"
headers = {"Authorization": f"Bearer {authorization}"}
r = requests.get(tickets_url, headers=headers)
if r.status_code != requests.codes.ok:
data = None
print("Error:", r.status_code)
else:
data = r.json()
return data
def launch_ticket_viewer(data):
if data:
print("********** ZENDESK TICKET VIEWER **********\nAre you ready for some customer support? View your following "
"tickets and use the menu below to get started.\n")
tickets = ticket_database.Tickets(data)
last_ticket = tickets.display_tickets()
user_instructions = f"\nSelect an option:\n[V] View Ticket Details --- " \
f"[N] Next Page --- [Q] Quit\n"
while True:
user_input = input(user_instructions)
if user_input.lower() == 'quit' or user_input.lower() == 'q':
print("\nExiting the Ticket Viewer program...")
break
elif user_input.lower() == 'v' or user_input.lower() == 'view' or user_input.lower() == 'n' or \
user_input.lower() == 'next':
num = tickets.execute_command(user_input, last_ticket)
if num >= 0:
last_ticket = num
else:
print("\nCommand not recognized.\n")
else:
print("Error: Could not retrieve tickets at this time. Please check with your system administrator.")
def main():
authorization = Constants.AUTHORIZATION_KEY
domain = Constants.DOMAIN
data = get_tickets(authorization, domain)
if data is not None:
launch_ticket_viewer(data)
return 1
else:
print("Error: Could not retrieve tickets at this time. Please check with your system administrator.")
return -1
if __name__ == "__main__":
main()