Python 阅读彼得的文章
我想知道是否有人能够通过pyOTRS阅读OTRS系统内的文章?我可以很好地连接并获得门票,我只是不知道如何获得门票的内容。我一直在查阅彼得的文件,但我被卡住了。关于阅读文章,有人有什么可以分享的吗?这里提到了PyOTRS的先决条件:。 完成这些操作后,可以采取以下步骤检索OTRS票证数据:Python 阅读彼得的文章,python,otrs,Python,Otrs,我想知道是否有人能够通过pyOTRS阅读OTRS系统内的文章?我可以很好地连接并获得门票,我只是不知道如何获得门票的内容。我一直在查阅彼得的文件,但我被卡住了。关于阅读文章,有人有什么可以分享的吗?这里提到了PyOTRS的先决条件:。 完成这些操作后,可以采取以下步骤检索OTRS票证数据: 通过创建客户端来启动连接 进行OTRS票证搜索 使用get\u Ticket.to\u dct()响应检索OTRS票证数据,包括动态字段和文章 from pyotrs import Article, Clie
from pyotrs import Article, Client, Ticket, DynamicField, Attachment
# Initializing
URL = config["url"]
USERNAME = config["username"]
PASSWORD = config["password"]
TICKET_LINK = config["ticketLink"]
# Create session
def createSession():
client = Client(URL, USERNAME, PASSWORD, https_verify=False)
client.session_create()
return client
# Retrieve tickets based on condition
def ticketData(client):
# Specify ticket search condition
data = client.ticket_search(Queues=['queue1Name', 'queue2Name'], States=['open'])
print("Number of tickets retrieved:" + str(len(data)))
# Iterating over all search results
if data[0] is not u'':
for ticket_id in data:
# Get ticket details
get_ticket = client.ticket_get_by_id(ticket_id, articles=1, attachments=1)
print(get_ticket)
q1 = "Ticket id: " + str(get_ticket.field_get("TicketID")) + "\nTicket number: " + str(get_ticket.field_get("TicketNumber")) + "\nTicket Creation Time: " + str(get_ticket.field_get("Created")) + "\n\nTicket title: " + get_ticket.field_get("Title")
print(q1)
# Based on to_dct() response we can access dynamic field (list) and article values
print(get_ticket.to_dct())
# Accessing dynamic field values
dynamicField3 = get_ticket.to_dct()["Ticket"]["DynamicField"][3]["Value"]
dynamicField12 = get_ticket.to_dct()["Ticket"]["DynamicField"][12]["Value"]
# Accessing articles
article = get_ticket.to_dct()["Ticket"]["Article"]
print(len(article))
# Iterating through all articles of the ticket (in cases where tickets have multiple articles)
for a1 in range(0, len(article)):
# Article subject
q2 = "Article " + str(a1+1) + ": " + get_ticket.to_dct()["Ticket"]["Article"][a1]["Subject"] + "\n"
print(q2)
# Article body
x = get_ticket.to_dct()["Ticket"]["Article"][a1]["Body"]
x = x.encode('utf-8') #encoded
q3 = "Body " + str(a1+1) + ": " + x + "\n"
print(q3)
# Ticket link for reference
q4 = "Ticket link: " + TICKET_LINK + ticket_id + "\n"
print(q4, end="\n\n")
def main():
client = createSession()
ticketData(client)
print("done")
main()