from BeautifulSoup import BeautifulSoup, Comment
import re,os
basename="storms-literature"
## step 1: generate the raw html file from the bib file
os.system("bibtex2html -dl -nodoc "+basename+".bib")
## step 2: generate the sectioned html file from the raw html file
f=open(basename+".html","r")
soup=BeautifulSoup(f.read())
f.close()
fw=open(basename+".html","w")
fw.write("\n\n
\n \nRACEWIN project: literature review on windstorms\n\n\n\n\n\n\n
RACEWIN project
\nLiterature review on windstorms
")
header = soup.find(text=re.compile("bibtex2html"))
fw.write(str(header)+"\n")
fw.write("\n")
fw.write("\n")
fw.write("\n")
dts=soup.findAll('dt')
dds=soup.findAll('dd')
nfields=len(dts)
if nfields!=len(dds):
print "We have a problem"
dic={"2011":2011,"2010":2010,"2009":2009,"2008":2008,"2007":2007,"2006":2006,"2005":"2005 and earlier"}
k=1
for i in range(nfields):
key=dts[i].contents[1]['name']
if key in dic.keys():
fw.write(""+str(dic[key])+".
"+"\n\n")
else:
dts[i].a.contents[0].replaceWith(str(k))
fw.write(dts[i].prettify()+"\n")
fw.write(dds[i].prettify()+"\n")
k=k+1
fw.write("
\n")
fw.write("
\n")
fw.write("\n")
fw.write(soup.p.prettify()+"\n")