Mercurial > repos > pablocarb > synbiodesign
view rpviz/py2html2.py @ 25:2f8af738e139 draft
planemo upload commit c74b3ff2329f69ac7b309cc7d9bdf7b9d78106fb-dirty
author | pablocarb |
---|---|
date | Fri, 05 Jul 2019 17:24:48 -0400 |
parents | fe78fd6b315a |
children |
line wrap: on
line source
# -*- coding: utf-8 -*- """ Created on Wed Jun 5 16:07:03 2019 @author: anael """ import json import os from bs4 import BeautifulSoup def html2(jsondata,outfile): htmlfile= open(os.path.join("new_html","template2.html")) soup = BeautifulSoup(htmlfile, 'html.parser') for key in jsondata.keys(): name=key obj=json.loads(jsondata[key]) elements=obj['elements'] element_script=soup.find(id="elements") #select the script section containing elements element_script.append('\n var '+name+'='+str(elements)) #to modify form=soup.find('form') new_tag = soup.new_tag("input") new_tag["type"] = "button" new_tag["value"]=name new_tag["onclick"]="displaynet("+name+')' form.append(new_tag) try: select=soup.find(id="selectbox") new_tag=soup.new_tag("option") new_tag["value"]=str(name) new_tag.append(name) select.append(new_tag) except: continue htmlfile.close() html = soup.prettify("utf-8") with open(os.path.join(outfile), "wb") as file: file.write(html)