-
Notifications
You must be signed in to change notification settings - Fork 5
/
visualize_localy.py
38 lines (29 loc) · 1000 Bytes
/
visualize_localy.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
37
38
#!/usr/bin/env python
"""
This module lets you run a command like:
java -jar tools/PlayGame.jar map.txt 100 100 log "./bot1" "./bot2" | \
python visualizer/visualize_localy.py
It then generates the visualisation and opens it in your browser. Awesome!
"""
import re
import sys
import os
import webbrowser
def generate(data, generated_path):
path = os.path.dirname(__file__)
template_path = os.path.join(path, 'index.php')
template = open(template_path, 'r')
content = template.read()
template.close()
php_re = re.compile(r"<\?php.*?\?>", re.S)
javascript = "var data = '%s';" % data
content = php_re.sub(javascript, content)
output = open(generated_path, 'w')
output.write(content)
output.close()
if __name__ == "__main__":
data = raw_input()
path = os.path.dirname(__file__)
generated_path = os.path.realpath(os.path.join(path, 'generated.htm'))
generate(data, generated_path)
webbrowser.open('file://'+generated_path)