commit 061d1ff95d50cb4c57ada49d70e08082e484f77f Author: Kolan Sh Date: Sun May 20 12:16:10 2012 +0400 Initial commit diff --git a/detect_encoding.py b/detect_encoding.py new file mode 100755 index 0000000..5a99c8b --- /dev/null +++ b/detect_encoding.py @@ -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'] diff --git a/detect_encoding_and_convert.sh b/detect_encoding_and_convert.sh new file mode 100755 index 0000000..7f40b8d --- /dev/null +++ b/detect_encoding_and_convert.sh @@ -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 +