View Single Post
Old 06-05-2014, 07:01 PM   #10
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,709
Karma: 205039118
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
No promises, but this seems to be working for me. I stayed strictly within Python ... so it's going to leave the original epub unchanged and create a new one with the desired changes.

Just like your original script, it's launched as follows:
Code:
./cm2em.py old.epub new.epub
There's not much in the way of error-checking, so that might need some work. And the script doesn't "fix" anything. If it wasn't a valid epub archive before, it's not going to be valid after. But by the same token ... if the original was a validated epub to begin with, the script shouldn't break it (structurally speaking, anyway). It just runs your conversion routine on any css files found in any zip archive (epub) you feed to it.

The file extension is .txt so I could upload it easily. Change it to .py if it amuses you.

EDIT: Got rid of an unnecessary conditional and changed it so if the stylesheet didn't need altering, it isn't unnecessarily rewritten. That way, all file properties (modification date, etc...) should stay the same (unless they were altered). Can't guarantee that Python's zlib compression implementation will result in a compressed size that exactly matches whatever was used to create the epub originally, but it should be close.
Attached Files
File Type: txt cm2em.txt (2.0 KB, 381 views)
File Type: txt cm2em_v2.txt (2.0 KB, 364 views)

Last edited by DiapDealer; 06-05-2014 at 08:53 PM.
DiapDealer is offline   Reply With Quote