Last active
March 29, 2024 12:37
-
-
Save asdf8601/2d3bc321405b1991277fd6001060df0d to your computer and use it in GitHub Desktop.
Revisions
-
mmngreco revised this gist
Mar 29, 2024 . 1 changed file with 8 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,24 +2,9 @@ """ Examples -------- $ pipx run https://gist.githubusercontent.com/mmngreco/2d3bc321405b1991277fd6001060df0d/raw/dot2ascii.py help $ pipx run https://gist.githubusercontent.com/mmngreco/2d3bc321405b1991277fd6001060df0d/raw/dot2ascii.py "graph {a -- b -- c}" $ echo "graph {rankdir=LR; a -- b -- c }" | pipx run https://gist.githubusercontent.com/mmngreco/2d3bc321405b1991277fd6001060df0d/raw/dot2ascii.py """ # /// script # requires-python = ">=3.10" @@ -46,7 +31,7 @@ def dot_to_ascii(dot: str, fancy: bool = True): return response def app(): import sys if len(sys.argv) > 1: text = sys.argv[1] @@ -57,3 +42,7 @@ def dot_to_ascii(dot: str, fancy: bool = True): text = sys.stdin.read() ascii = dot_to_ascii(text) print(ascii) if __name__ == '__main__': app() -
mmngreco created this gist
Mar 29, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ #!python3 """ Examples -------- >>> pipx run main.py help ... text = ''' ... graph { ... rankdir=LR ... A [label="Christmas"] ... B [label="Go shopping"] ... C [label="Let me think"] ... D [label="Laptop"] ... E [label="iPhone"] ... F [label="Car"] ... A -> B [label="Get money"] ... B -> C ... C -> D [label="One"] ... C -> E [label="Two"] ... C -> F [label="Three"] ... } ... ''' """ # /// script # requires-python = ">=3.10" # dependencies = [ # "requests", # ] # /// import requests def dot_to_ascii(dot: str, fancy: bool = True): url = 'https://dot-to-ascii.ggerganov.com/dot-to-ascii.php' boxart = 0 if fancy: # use nice box drawing char instead of + , | , - boxart = 1 params = { 'boxart': boxart, 'src': dot, } response = requests.get(url, params=params).text if response == '': raise SyntaxError('DOT string is not formatted correctly') return response if __name__ == '__main__': import sys if len(sys.argv) > 1: text = sys.argv[1] if text == "help": print("Usage: python main.py [dot_string]") sys.exit(0) else: text = sys.stdin.read() ascii = dot_to_ascii(text) print(ascii)