generated from just-the-docs/just-the-docs-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathextract.py
39 lines (26 loc) · 905 Bytes
/
extract.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
#!/opt/homebrew/bin/python3
from bs4 import BeautifulSoup
with open('extract.css', 'r') as f:
css = f.read()
with open('sql3.html', 'r') as f:
contents = f.read()
soup = BeautifulSoup(contents, 'lxml')
for sect in soup.find_all('section'):
print(sect.h4)
svg = sect.svg
svg["xmlns"] = "http://www.w3.org/2000/svg"
del svg["style"]
viewbox = svg["viewbox"]
items = viewbox.split(' ')
svg['height'] = items[3]
new_style = soup.new_tag("style")
new_style.string = css
svg.append(new_style)
# get rid of a's
for a in svg.find_all('a'):
del a["xlink:href"]
filename = "./../../assets/images/sql-guide/" + sect.h4.string + '.svg'
text_file = open(filename, "w")
svgbody = svg.prettify()
n = text_file.write(svgbody)
text_file.close()