-
-
Save toc21c/5214e9817a35bb726c71 to your computer and use it in GitHub Desktop.
fix-sami.py python3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
import tempfile | |
import shutil | |
def fix(src_filename, dst_filename, src_enc, dst_enc): | |
with open(src_filename, mode='r', encoding=src_enc) as file_in: | |
with open(dst_filename, mode='w', encoding=dst_enc) as file_out: | |
file_out.write("""<SAMI> | |
<HEAD> | |
<TITLE>..</TITLE> | |
<STYLE TYPE="text/css"> | |
<!-- | |
P { margin-left:2pt; margin-right:2pt; margin-bottom:1pt; | |
margin-top:1pt; font-size:20pt; text-align:center; | |
font-family:Arial, Sans-serif; font-weight:bold; color:white; | |
} | |
.KRCC { Name:Korean; lang:ko-KR; } | |
--> | |
</STYLE> | |
</HEAD> | |
<BODY> | |
""") | |
file_out.write(file_in.read()) | |
file_out.write(""" | |
</BODY> | |
</SAMI> | |
""") | |
if __name__ == '__main__': | |
SRC_ENC = 'cp949' | |
DST_ENC = 'utf8' | |
for src_filename in sys.argv[1:]: | |
print("SRC: ", src_filename) | |
temp_filename = tempfile.mktemp() | |
try: | |
fix(src_filename, temp_filename, | |
SRC_ENC, DST_ENC) | |
os.rename(src_filename, src_filename + '.BACKUP-FIX-SAMI') | |
shutil.copy(temp_filename, src_filename) | |
except exc: | |
print('FAIL!', exc, file=sys.stderr) | |
finally: | |
os.unlink(temp_filename) | |
""" | |
grep --null -Li \<sami *.smi |xargs -0 python3 ~/local/bin/fix-sami.py | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment