Python Forum

Full Version: capturing multiline output for number of parameters
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using ttp template to parse a data from command line

I followed the following link while writing below code:
https://python-forum.io/thread-40584.html
https://ttp.readthedocs.io/en/latest/FAQ...ine-output

import json
from ttp import ttp

temp = """
<group>
System Info {{_start_}}
IPv4 configuration : {{ ipv4_configuration |  _exact_ }}
IPv6 configuration : {{ ipv6_configuration |  _exact_ }}

<group name="details">
Description  : {{ _start_ }}
{{description|_line_ | joinmatches("")}}
Modified details : {{ _start_ }}
{{modified_details|_line_|joinmatches("")}}
System Description : {{ _start_ }}
{{system_description|_line_|joinmatches("")}}
Technical Support : {{ _start_ }}
{{technical_support|_line_|joinmatches("")}}
{{ _end_ }}
</group>
<group name="ip_details">
  {{from}} {{to}}
</group>

</group>
"""

data_to_parse = """
===============================================================================
System Info
===============================================================================
IPv4 configuration : Disabled
IPv6 configuration : Enabled
Description        : #It is used to connect to the network
                      using the IPV6 and IPV4 which is
                      secure
Modified details   :  The code was modfied by jim corbett .Details
                      are [email protected]
System Description :  #Cisco IOS Software, Catalyst 1234 L3 Switch Software (cat1234e-ENTSERVICESK9-M), 
                       Version 1534.1(1)SG, RELEASE SOFTWARE (fc3)
Technical Support  :  http://www.cisco.com/techsupport Copyright (c) 1986-2012 by Cisco Systems, Inc.
                      Compiled Sun 15-Apr-12 02:35 by p
IP details         :
  From               To
  10.12.21.123       32.32.32.32
  10.12.21.123       32.32.32.32
  
"""
parser = ttp(data=data_to_parse, template=temp)
parser.parse()

result = json.loads(parser.result(format="json")[0])[0]
print(result)
My output is this:

Output:
[{'ip_details': [{'from': 'From', 'to': 'To'}, {'from': '10.12.21.123', 'to': '32.32.32.32'}, {'from': '10.12.21.123', 'to': '32.32.32.32'}], 'ipv4_configuration': 'Disabled', 'ipv6_configuration': 'Enabled'}]
My expected out put is like below:
Output:
{'ip_details': [{'from': '10.12.21.123', 'to': '32.32.32.32'}, {'from': '10.12.21.123', 'to': '32.32.32.32'}], 'ipv4_configuration': 'Disabled', 'ipv6_configuration': 'Enabled',"description" :"#It is used to connect to the networkusing the IPV6 and IPV4 which is secure","modified_details":"The code was modfied by jim corbett .Details are [email protected]","system_description":"#Cisco IOS Software, Catalyst 1234 L3 Switch Software (cat1234e-ENTSERVICESK9-M), Version 1534.1(1)SG, RELEASE SOFTWARE (fc3)","technical_support":"http://www.cisco.com/techsupport Copyright (c) 1986-2012 by Cisco Systems, Inc.Compiled Sun 15-Apr-12 02:35 by p"}
Please shed light on how to proceed
Quit starting new posts for the same question, and stop spoon-feeding the question.
The reason i added {{_end__}} was as it explicitly indicates end of the group.
.....