blob: bd0ff3cf106160e1610c74d58a15aa2254be1eda (
plain)
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
|
#!../flask/bin/python
"""
usage: bug show [options] <ticket_id>
-h, --help Print this help text
"""
from docopt import docopt
from textwrap import indent
from datetime import datetime
import json, requests
if __name__ == '__main__':
print(docopt(__doc__))
def entrypoint(args):
print(args)
api_endpoint = args['--uri'] + '/api/1.0/ticket/'
r = requests.get(api_endpoint + args['<ticket_id>'], verify=False)
ticket = json.loads(r.text).get('ticket')
print(ticket)
print(show_ticket(ticket))
def show_ticket(ticket):
output = '[TBT#{}] '.format(ticket['id'])
if 'deleted' in ticket and ticket['deleted'] == True:
output += '[DELETED] '
output += '[{}] '.format(ticket['status'])
output += '{}\n'.format(ticket['summary'])
if ticket['status'] != 'open':
output += 'Reason: {}\n'.format(ticket['reason'])
output += 'Opened by: {} <{}>\n'.format(ticket['opened_by']['nickname'], ticket['opened_by']['email'])
output += 'Opened at: {} UTC\n'.format(datetime.strptime( ticket['opened_at'], "%Y-%m-%dT%H:%M:%S" ))
if ticket['updated_at']:
output += 'Updated at: {} UTC\n'.format(datetime.strptime(ticket['opened_at'], "%Y-%m-%dT%H:%M:%S" ))
output += '\n' + indent('{}'.format(ticket['body']), ' ') + '\n'
return output
|