Initial commit

This commit is contained in:
Kolan Sh 2012-05-20 12:16:10 +04:00
commit 061d1ff95d
2 changed files with 23 additions and 0 deletions

12
detect_encoding.py Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/python
import sys
import glob
from chardet.universaldetector import UniversalDetector
detector = UniversalDetector()
detector.reset()
contents=file(sys.argv[1], 'rb').read()
detector.feed(contents)
detector.close()
print detector.result['encoding']

11
detect_encoding_and_convert.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
toenc=$1
fname="$2"
enc=`detect_encoding.py "$fname"`
echo "Encoding=$enc"
[ "$enc" != "None" ] && iconv -f $enc -t $toenc "$fname" -o "$fname.iconv" && mv "$2".iconv "$2" || rm -f "$2".iconv
exit 0