radiaSRT/gen_html.py

64 lines
2.2 KiB
Python
Raw Permalink Normal View History

2011-09-03 14:28:41 +00:00
from ox.text import findRe
2011-09-05 11:58:38 +00:00
import json
import codecs
2011-09-03 14:28:41 +00:00
2012-01-20 14:48:35 +00:00
2011-12-22 12:34:02 +00:00
def JSONtoHTML():
data = json.loads(open("radia.json").read())
html = ''
counter = 1
for d in data:
html += '<div class="container" data-name="%s" data-padma="%s">\n' % (d['name'], d['hid'],)
html += ' <div class="title"><span class="counter">%d&gt;</span> %s</div>\n' % (counter, d['title'],)
html += ' <div class="time">%s</div>\n' % (d['dt-time'],)
html += "</div>\n\n"
2011-12-22 12:34:02 +00:00
counter += 1
indexFile = codecs.open("index.html", mode="w", encoding="utf-8")
header = open("header.html").read()
footer = open("footer.html").read()
indexFile.write(header)
indexFile.write(html)
indexFile.write(footer)
indexFile.close()
2011-09-03 14:28:41 +00:00
def do():
2011-09-05 11:58:38 +00:00
f = codecs.open("ChronoArr_Srt.txt", mode="r", encoding="utf-8")
data = json.loads(open("radia.json").read())
2011-09-03 14:28:41 +00:00
txt = f.read()
tapes = txt.split("***")
2011-09-05 11:58:38 +00:00
indexHtml = u''
counter = 0
2011-09-03 14:28:41 +00:00
for t in tapes:
2011-09-05 11:58:38 +00:00
if counter >= len(data):
break
meta = data[counter]
padmaId = meta['hid']
audioFile = meta['name'] + u'.wav'
2011-09-03 14:28:41 +00:00
fullTxt = t.strip()
titleReg = r'Title: (.*?)\n'
2011-09-03 14:35:29 +00:00
timeReg = r'Time: (.*?)\n'
2011-09-03 14:37:27 +00:00
time = findRe(fullTxt, timeReg)
2011-09-03 14:28:41 +00:00
outfile = "tapes/%d.html" % (counter,)
title = findRe(fullTxt, titleReg)
print title
2011-09-05 11:58:38 +00:00
indexHtml += "<a target='_blank' href='%s'>%s</a><br />Time: %s<br/>\n" % (outfile, title, time,)
indexHtml += "<a target='_blank' href='http://pad.ma/%s'>View on Padma</a><br />\n" % (padmaId,)
2011-12-22 12:34:02 +00:00
# audioHtml = "<audio controls='controls' src='wav/%s' preload='none'></audio><br /><br />\n\n" % (audioFile,)
2011-09-05 11:58:38 +00:00
print audioHtml
indexHtml += audioHtml
out = codecs.open(outfile, mode="w", encoding="utf-8")
out.write("<audio controls='controls' src='../wav/%s'></audio><br /><br /><pre>%s</pre>" % (audioFile, fullTxt,))
2011-09-03 14:28:41 +00:00
out.close()
counter += 1
2011-09-05 11:58:38 +00:00
indexFile = codecs.open("index.html", mode="w", encoding="utf-8")
2011-12-22 12:34:02 +00:00
header = open("header.html").read()
footer = open("footer.html").read()
indexFile.write(header)
2011-09-03 14:28:41 +00:00
indexFile.write(indexHtml)
2011-12-22 12:34:02 +00:00
indexFile.write(footer)
2011-09-03 14:28:41 +00:00
indexFile.close()
f.close()