-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path__init__.py
36 lines (30 loc) · 1000 Bytes
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import atexit
import json
import os
from . import randomize as Randomize
from .commander import Commander
from .layouts import *
from .tracers import *
__all__ = (
"Randomize", "Commander",
"Array1DTracer", "Array2DTracer", "ChartTracer", "GraphTracer", "LogTracer", "Tracer",
"HorizontalLayout", "Layout", "VerticalLayout"
)
@atexit.register
def execute():
commands = json.dumps(Commander.commands, separators=(",", ":"))
if os.getenv("ALGORITHM_VISUALIZER"):
with open("visualization.json", "w", encoding="UTF-8") as file:
file.write(commands)
else:
import requests
import webbrowser
response = requests.post(
"https://algorithm-visualizer.org/api/visualizations",
headers={"Content-type": "application/json"},
data=commands
)
if response.status_code == 200:
webbrowser.open(response.text)
else:
raise requests.HTTPError(response=response)