View Single Post
Old 02-13-2011, 01:54 PM   #6
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,590
Karma: 28548962
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Code:
from calibre import walk

for path in walk('.'):
   if os.path.splitext(path)[1:].lower() in ('html', 'htm'):
       with open(path, 'r+b') as f:
           raw = f.read()
           raw = raw.decode('utf-8')
           for pat, func in self.preprocess_regexps:
                 raw = pat.sub(func, raw)
           f.seek(0)
           f.truncate()
           f.write(raw.encode('utf-8'))
This will need some adjustments, of course.
kovidgoyal is online now   Reply With Quote