txt2htm.py
# -*- coding: utf-8 -*-
import os, sys
import glob
if len(sys.argv) ==2:
pattern = sys.argv[1]
else:
print 'usage: txt2htm.py *.txt '
print 'generate ?????.htm '
sys.exit(1)
for f1 in glob.glob(pattern):
print f1
fn,ext = os.path.splitext(f1)
if ext != '.txt':
print 'Error: %s is not txt file ' % f1
sys.exit(4)
headline ="""<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title> 新概念英语 %s </title>
</head>
<body>
""" % (fn)
audio ="""
<audio controls="controls">
<source src="./%s.mp3" type="audio/mp3" />
</audio>
""" % (fn)
fp1 = open(f1,'r')
f2 = fn +'.htm'
fp2 = open(f2,'w')
fp2.write(headline)
ln =0
for line in fp1:
if len(line.strip()) ==0:
continue
ln +=1
if ln ==1:
alist = line.strip().split(' ',1)
aline = '<h3>'+alist[1]+'</h3>'
fp2.write(aline)
else:
if line.startswith("对应音频"):
fp2.write(audio)
elif line.startswith("New Word"):
aline = '<hr>\n<br>'+line
fp2.write(aline)
elif line.startswith("New word"):
aline = '<hr>\n<br>'+line
fp2.write(aline)
elif line.startswith("Notes on"):
aline = '<hr>\n<br>'+line
fp2.write(aline)
elif line.startswith("参考译文"):
aline = '<hr>\n<br>'+line
fp2.write(aline)
elif line.startswith("在线收听地址"):
break
elif line.startswith("document.onclick"):
break
else:
aline = '<br>'+line
fp2.write(aline)
#
fp2.write("</p>\n</body>\n</html>\n")
fp1.close()
fp2.close()
#
分享到:
相关推荐
Python: Learn Python in 24 Hours: Complete Beginners Guide English | 19 July 2016 | ASIN: B01IRGB6MY | 110 Pages If you are one of them who easily get scared of Python’s long, complicated code, then...
从零开始学Python:Python语言中的变量.docx从零开始学Python:Python语言中的变量.docx从零开始学Python:Python语言中的变量.docx从零开始学Python:Python语言中的变量.docx从零开始学Python:Python语言中的变量...
从零开始学Python:第一个Python程序.docx从零开始学Python:第一个Python程序.docx从零开始学Python:第一个Python程序.docx从零开始学Python:第一个Python程序.docx从零开始学Python:第一个Python程序.docx从零...
《零基础轻松学Python:青少年趣味编程(全彩版)》案例文件.zip
可爱的 Python:将 XML 和 Python结合起来
圆方圆Python入门:超适合小白的python新手教程.pdf圆方圆Python入门:超适合小白的python新手教程.pdf圆方圆Python入门:超适合小白的python新手教程.pdf圆方圆Python入门:超适合小白的python新手教程.pdf圆方圆...
Python毕业设计:车牌识别系统源码Python毕业设计:车牌识别系统源码Python毕业设计:车牌识别系统源码Python毕业设计:车牌识别系统源码Python毕业设计:车牌识别系统源码Python毕业设计:车牌识别系统源码Python...
本书包含快速学习Python编程的经过验证的步骤和策略 而且很容易。 Python 是一种强大且灵活的编程语言。 它使用简洁易学 语法使程序员能够编写更多代码并开发更复杂的代码 程序在更短的时间内。 Python:终极初学者...
Python: Real World Machine Learning by Prateek Joshi English | 14 Nov. 2016 | ASIN: B01N74UY6B | ISBN-13: 9781787123212 | 983 Pages | MOBI/EPUB/PDF | 53.2 MB Learn to solve challenging data science ...
Python: Practical Python Programming For Beginners and Experts English | 9 July 2016 | ISBN: 1535192976 | 170 Pages Start work on your website, app, or search engine today with this practical Python ...
Curso-python:python的英语翻译
功能描述:此程序使用Python编写 1. 可以将 单个SVG图片文件 转换为 【128/64/48/32/16】 任一尺寸的 ico 图片。 2. 可以将 一个目录下的所有SVG图片,同时转换为对应的 任意尺寸的 ico 图片。 3. 输入的 ico图标...
Python:pygame飞机大战源码和素材
基于深度学习的英语、法语翻译预处理,适合广大的深度学习者
Python实现将json文件转为shapefile
82篇顶会巨佬撰写的入门机器学习与深度学习的神书
python把⽂本转换为html_Python基础教程——把⽂本转为 HTML格式 功能:将⽂本⽂件转换成html格式的⽂档。 ⽅法: 1.添加初始标签 2.智能分段 #util.py def lines(file): #遍历⽂本⽂件,⽤⽣成器保存每⾏ for line ...
《Python编程:从入门到实践》源代码文件