Skip to content

Commit

Permalink
print out original storage request
Browse files Browse the repository at this point in the history
  • Loading branch information
akea013 committed Sep 23, 2019
1 parent 8f76944 commit e9875d7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
9 changes: 8 additions & 1 deletion snow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import sys
import click
from util import login, list_tasks, show_ticket, patch
from util import login, list_tasks, show_ticket, ticket_yaml, patch

class AliasedGroup(click.Group):
def get_command(self, ctx, cmd_name):
Expand Down Expand Up @@ -61,6 +61,13 @@ def show(ctx, number):
"""Show a ticket"""
show_ticket.get_and_print_ticket(ctx.obj, number)

@snow.command(name="extract_yaml")
@click.argument('number')
@click.pass_context
def download_yaml(ctx, number):
"""Show a ticket"""
ticket_yaml.extract(ctx.obj, number)

@snow.command(name="comment")
@click.argument('number')
@click.pass_context
Expand Down
1 change: 1 addition & 0 deletions util/show_ticket.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from bs4 import BeautifulSoup
import json
import re

fields = [
("Ticket details", [
Expand Down
32 changes: 32 additions & 0 deletions util/ticket_yaml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import json
import re

def extract(ctx, args):
BASE_URL = ctx["BASE_URL"]
s = ctx["s"]
query = "number=" + args
url = BASE_URL + "/api/now/table/task"
params = {
"sysparm_query": query,
"sysparm_display_value": "true",
}
r = s.get(url, params=params)
r = r.json()
if 'error' in r:
print(r["error"]["message"])
return
if not r['result']:
print("Ticket not found")
return
ticket = r['result'][0]
p = re.compile(r'^General$', re.M)
ticket_start_position = re.search(p, ticket['comments']).start()
with open('orig_request.yaml','w') as orig_request:
orig_request.write(ticket['comments'][ticket_start_position:])
print(ticket["comments"])
print(json.dumps(ticket, indent=4, sort_keys=True))

# vim: fenc=utf-8: ft=python:sw=4:et:nu:fdm=indent:fdn=1:syn=python

0 comments on commit e9875d7

Please sign in to comment.