Skip to content

Instantly share code, notes, and snippets.

@Hermann-SW
Last active March 15, 2024 01:40
Show Gist options
  • Save Hermann-SW/ec9bfcb59a2ad0b64336519c48286ad6 to your computer and use it in GitHub Desktop.
Save Hermann-SW/ec9bfcb59a2ad0b64336519c48286ad6 to your computer and use it in GitHub Desktop.
Open graphviz .dot file in GraphvizFiddle in browser
#!/usr/bin/env python
""" view graphviz file """
# pylint: disable=C0103
import sys
import webbrowser
import urllib.parse
import time
if len(sys.argv)<3:
print("Format: "+sys.argv[0]+" browser dotfile")
else:
B=webbrowser.get(sys.argv[1])
with open(sys.argv[2], encoding="utf-8") as f:
s=urllib.parse.quote("".join(line for line in f))
T=str(int(time.time()))
B.open("https://stamm-wilbrandt.de/GraphvizFiddle/2.1.2/?"+T+"#"+s)
@Hermann-SW
Copy link
Author

New gist "straight_line_graphviz.cpp" generates the complete graphviz graph as output:
https://gist.github.com/Hermann-SW/99d151a273d290ee0d843c79b2da26a8?permalink_comment_id=4985753#gistcomment-4985753

pi@raspberrypi5:~ $ ./straight_line_graphviz | head -5
graph {
  layout=neato
  node [shape=none]
  0 [pos="0,0!"]
  1 [pos="16,0!"]
pi@raspberrypi5:~ $ ./straight_line_graphviz | tail -3
  8--5
  9--6
}
pi@raspberrypi5:~ $ 

So now GraphvizFiddle.py is of real help and opens result directly in browser:

pi@raspberrypi5:~ $ GraphvizFiddle.py firefox <(./straight_line_graphviz)
pi@raspberrypi5:~ $ 

@Hermann-SW
Copy link
Author

Revision 3 does use webbrowser module instead of os.system():

pi@raspberrypi5:~ $ pylint /usr/local/bin/GraphvizFiddle.py 

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

pi@raspberrypi5:~ $ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment