【问题标题】:Read Articles in PyOTRS [closed]阅读 PyOTRS 中的文章 [关闭]
【发布时间】:2020-05-28 18:11:30
【问题描述】:

我想知道是否有人能够通过 pyOTRS 阅读 OTRS 系统票证中的文章?我能够连接并获得门票,但我无法找到如何获得门票的内容。我一直在查看 PyOTRS 文档,但我被卡住了。关于阅读文章,有人有什么可以分享的吗?

【问题讨论】:

    标签: python otrs


    【解决方案1】:

    这里提到了 PyOTRS 的先决条件:https://pypi.org/project/PyOTRS/。 完成这些后,可以采取以下步骤来检索 OTRS 票证数据:

    1. 通过创建客户端来启动连接。
    2. 已进行 OTRS 票证搜索。
    3. 使用 get_ticket.to_dct() 响应检索 OTRS 票证数据,包括动态字段和文章。
    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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-10
      • 2018-02-20
      • 2012-01-23
      • 1970-01-01
      • 1970-01-01
      • 2010-11-23
      相关资源
      最近更新 更多