[Python] How to use correctly Pyflowchart output

Discussão em 'Python' iniciado por Stack, Maio 6, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to use pyflowchart package that print this output on VSC terminal after using the command python -m pyflowchart 2-4-8.py:

    op2=>operation: from netmiko import ConnectHandler
    op4=>operation: from getpass import getpass
    op6=>operation: from datetime import datetime
    op8=>operation: import logging
    op10=>operation: import snoop
    sub12=>subroutine: logging.basicConfig(filename='script.log', filemode='w',
    level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
    op14=>operation: password = getpass()
    op16=>operation: Device1 = {'device_type': 'juniper_junos', 'ip': 'x.x.x.x', 'username':
    'user', 'password': password}
    op18=>operation: Device2 = {'device_type': 'juniper_junos', 'ip': 'x.x.x.x', 'username':
    'user', 'password': password}
    op20=>operation: Device3 = {'device_type': 'juniper_junos', 'ip': 'x.x.x.x', 'username':
    'user', 'password': password}
    op22=>operation: route = input('Route to verify: ')
    op24=>operation: command = 'show version | match Hostname'
    op26=>operation: command1 = f'show route {route} | match "localpref|>"'
    op28=>operation: clear_txt = open('Interfaces.txt', 'w')
    op30=>operation: Interfaces = open('Interfaces.txt', 'w')
    cond33=>condition: for device in (Device1, Device2, Device3)
    op126=>operation: net_connect = ConnectHandler(**device)
    op128=>operation: output = net_connect.send_command(command)
    op130=>operation: output1 = net_connect.send_command(command1)
    op132=>operation: now = datetime.now().strftime('%d/%m/%Y %H:%M')
    op134=>operation: head = ('-' * 65)
    op136=>operation: dev = output.split()[(- 1)]
    sub138=>subroutine: print(f'''{head}
    {now} --> ### HOSTNAME: {dev} ###
    {head}''', file=Interfaces)
    op140=>operation: output1 = output1.replace(',', '').split('\n')
    cond143=>condition: for line in output1
    op180=>operation: line = line.split()
    cond183=>condition: if ('localpref' in line)
    op187=>operation: ldata = line[(line.index('localpref') + 1)]
    cond192=>condition: if ('via' in line)
    op196=>operation: vdata = line[(line.index('via') + 1)][:(- 2)]
    op198=>operation: command2 = f'show interface {vdata} descriptions'
    op200=>operation: output2 = net_connect.send_command(command2)
    op202=>operation: ddata = output2[66:]
    op204=>operation: result = f'{now} --> localpref {ldata} --> via {vdata} --> {ddata}'
    sub206=>subroutine: print(result, file=Interfaces)
    sub216=>subroutine: Interfaces.close()

    op2->op4
    op4->op6
    op6->op8
    op8->op10
    op10->sub12
    sub12->op14
    op14->op16
    op16->op18
    op18->op20
    op20->op22
    op22->op24
    op24->op26
    op26->op28
    op28->op30
    op30->cond33
    cond33(yes)->op126
    op126->op128
    op128->op130
    op130->op132
    op132->op134
    op134->op136
    op136->sub138
    sub138->op140
    op140->cond143
    cond143(yes)->op180
    op180->cond183
    cond183(yes)->op187
    op187->cond143
    cond183(no)->cond192
    op196->op198
    op198->op200
    op200->op202
    op202->op204
    op204->sub206
    sub206->cond143
    cond192(no)->cond143
    cond143(no)->cond33
    cond33(no)->sub216


    I tried to read on https://pypi.org/project/pyflowchart/ how to use this output but for me is not clear, I tried to past this on markdown editor, I tried to use https://flowchart.js.org/ and I tried to create a .flowchart file but I can't figure out what to do. So my question is, can someone point me out how can I convert this output in a grafical flowchart?

    Thanks!

    Continue reading...

Compartilhe esta Página