forked from spacetelescope/jdat_notebooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddPlaceholder.py
More file actions
26 lines (19 loc) · 806 Bytes
/
addPlaceholder.py
File metadata and controls
26 lines (19 loc) · 806 Bytes
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
import os
import sys
import bs4
filepath = sys.argv[1]
with open(filepath, 'rb') as stream:
soup = bs4.BeautifulSoup(stream.read().decode('utf-8'), 'lxml')
cell_data = []
# Search out for widgets and place placeholder tag
#for widget in soup.findAll('div', {'class': ['cell_output docutils container']}):
for widget in soup.findAll('script', type='application/vnd.jupyter.widget-view+json'):
placeholder = soup.new_tag('img align=center height=auto width=50%', src='../../jdaviz_placeholder_new.png')
widget.insert_after(placeholder)
stream.close()
html=soup.prettify()
with open(filepath, "wb") as file:
file.write(html.encode('utf-8'))
###
# 777 <div class="cell_output docutils container">
# 778 <script type="application/vnd.jupyter.widget-view+json">