-
Notifications
You must be signed in to change notification settings - Fork 4
/
wrl2html.py
50 lines (44 loc) · 1.4 KB
/
wrl2html.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
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
from re import sub
from sys import stderr
from traceback import print_exc
import sys
import requests
import getopt
wrl_file = 'simulation.wrl'
html_file = 'simulation.html'
opts, args = getopt.getopt(sys.argv[1:], '', ['wrl=', 'html='])
for opt, arg in opts:
if opt in ('--wrl'):
wrl_file = arg
elif opt in ('--html'):
html_file = arg
API_ENDPOINT = "https://doc.instantreality.org/tools/x3d_encoding_converter/convert/"
with open(wrl_file, 'r') as file:
wrl_data = file.read()
data = {'input_encoding': 'CLASSIC', 'output_encoding': 'HTML5', 'input_code': wrl_data}
r = requests.post(url=API_ENDPOINT, data=data)
output = re.search('<td class="code">(.+)</td></tr></table></pre>', r.text.replace('\n', ''))
def remove_html_tags(data):
p = re.compile(r'<.*?>')
return p.sub('', data)
def unescape(s):
s = s.replace("<", "<")
s = s.replace(">", ">")
s = s.replace("'", "'")
s = s.replace("&", "&")
return s
html_file = open(html_file, "w")
pre_html = unescape(remove_html_tags(output.group(1)))
html_file.write(pre_html
.replace("<body>", "<body bgcolor='000'>")
.replace("400px", "1", 1)
.replace("400px", "1", 1)
.replace("0.7", "0.75")
.replace(" <", '\n\t\t\t<')
.replace(" <", '\n\t\t<')
.replace(" <", '\n\t<')
)
html_file.close()