Mercurial > repos > pablocarb > synbiodesign
comparison rpviz/py2html2.py @ 16:fe78fd6b315a draft
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
| author | pablocarb |
|---|---|
| date | Tue, 11 Jun 2019 11:42:40 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 15:785b6253af1f | 16:fe78fd6b315a |
|---|---|
| 1 # -*- coding: utf-8 -*- | |
| 2 """ | |
| 3 Created on Wed Jun 5 16:07:03 2019 | |
| 4 | |
| 5 @author: anael | |
| 6 """ | |
| 7 | |
| 8 import json | |
| 9 import os | |
| 10 from bs4 import BeautifulSoup | |
| 11 | |
| 12 | |
| 13 def html2(jsondata,outfile): | |
| 14 | |
| 15 htmlfile= open(os.path.join("new_html","template2.html")) | |
| 16 soup = BeautifulSoup(htmlfile, 'html.parser') | |
| 17 | |
| 18 for key in jsondata.keys(): | |
| 19 name=key | |
| 20 obj=json.loads(jsondata[key]) | |
| 21 elements=obj['elements'] | |
| 22 | |
| 23 element_script=soup.find(id="elements") #select the script section containing elements | |
| 24 element_script.append('\n var '+name+'='+str(elements)) #to modify | |
| 25 | |
| 26 form=soup.find('form') | |
| 27 new_tag = soup.new_tag("input") | |
| 28 new_tag["type"] = "button" | |
| 29 new_tag["value"]=name | |
| 30 new_tag["onclick"]="displaynet("+name+')' | |
| 31 form.append(new_tag) | |
| 32 try: | |
| 33 select=soup.find(id="selectbox") | |
| 34 new_tag=soup.new_tag("option") | |
| 35 new_tag["value"]=str(name) | |
| 36 new_tag.append(name) | |
| 37 select.append(new_tag) | |
| 38 except: | |
| 39 continue | |
| 40 | |
| 41 htmlfile.close() | |
| 42 | |
| 43 html = soup.prettify("utf-8") | |
| 44 with open(os.path.join(outfile), "wb") as file: | |
| 45 file.write(html) |
