Write HTML versions of HP Basic Text Files


In [1]:
import os
os.chdir(r'C:\Share\HPBASIC_ASCII')
files=os.listdir(os.getcwd())
print files


['CALREP71_COMMA.txt', 'CAP.txt', 'DMULTI1_04d.txt', 'DMULTI1_04E.TXT', 'evaluate.txt', 'FINDLEN.TXT', 'LINEPAR.txt', 'lrmcal.txt', 'MEASLPX.txt', 'Multical.txt', 'verify.txt']

In [2]:
HTML_PREFIX="""<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>%s</title>
    <link href="prism.css" rel="stylesheet" />
</head>
<body>
<h1> A highlighted Plain Text version of %s Basic Program</h1>
<pre><code class="language-basic"><script>"""
HTML_POSTFIX="""</script>

</code></pre>

<script src="prism.js" data-default-language="markup"></script>
</body>
</html>"""

In [3]:
for file_name in files:
    in_lines=[]
    in_file=open(file_name,'r')
    for line in in_file:
        in_lines.append(line)
    out_file=open(os.path.join(r'c:\Share',file_name.replace('.txt','.html').replace('.TXT','.html')),'w')
    out_file.write(HTML_PREFIX%(file_name,file_name))
    for line in in_lines:
        out_file.write(line)
    out_file.write(HTML_POSTFIX)
    out_file.close()

In [9]:



<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CALREP 7.1</title>
    <link href="prism.css" rel="stylesheet" />
</head>
<body>
<h1> A highlighted Plain Text version of CALREP HP Basic Program</h1>
<pre><code class="language-basic"><script>

In [ ]: