Last active
August 13, 2016 03:25
-
-
Save GeoffWilliams/02b379603b7055cffb456fd6bb26c111 to your computer and use it in GitHub Desktop.
Convert copy and pasted plaintext zendesk support ticket data into a html table - you can then open it in excel and manipulate the data :) how to use: copy the body of the helpdesk ticket and paste into a plain text file called ticket.txt, then run this script and capture the output. Save as .xls to open in excel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import textwrap | |
| def format_header(date, user): | |
| output = "<tr><td>{date}</td><td>{user}</td><td><pre>".format( | |
| date=date, | |
| user=user, | |
| ) | |
| return output | |
| with open('ticket.txt') as f: | |
| content = f.readlines() | |
| output="<table border='1'>" | |
| # first record does not contain 'user' so we need skip one | |
| # place behind so that elements appear in front of the cursor | |
| # in the correct position | |
| i = -1 | |
| transcript = [] | |
| record = "" | |
| while i < len(content): | |
| # records break on 'user' | |
| if content[i] == "user\n" or i==-1: | |
| if i > 0: | |
| # close previous table row if not the first one | |
| record += "</pre></td></tr>" | |
| transcript.append(record) | |
| # filter badge | |
| if content[i+1] == "badge\n": | |
| j = 1 | |
| else: | |
| j = 0 | |
| record = format_header( | |
| content[i+j+2], | |
| content[i+j+1] | |
| ) | |
| # skip out of the header | |
| i += j+2 | |
| else: | |
| record += textwrap.fill(content[i],80, drop_whitespace=False, replace_whitespace=False) | |
| i += 1 | |
| # close the last record | |
| record = record + "</pre></td></tr>" | |
| transcript.append(record) | |
| # reverse the transcript and print the table | |
| transcript.reverse() | |
| output += "\n".join(transcript) | |
| output += "</table>" | |
| print output |
Author
Author
now prints in reverse order (order of events)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for some reason firefox only prints the first 3 pages, chrome works fine