Created
August 25, 2015 13:10
-
-
Save ilius/b8021278215ac7bbb3fd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
# recode a file from arabic windows(windows-1256) to utf8 | |
import sys, os | |
def winArabicToUtf8(s, ar2fa=True): | |
u = s.decode('windows-1256') | |
if ar2fa: | |
for item in [ | |
(u'ي',u'ی'), | |
(u'ك',u'ک'), | |
(u'ۀ',u'هٔ'), | |
(u' ِ', u'ِ'), | |
]: | |
u = u.replace(item[0], item[1]) | |
return u.encode('utf8') | |
s = file(sys.argv[1]).read() | |
ws = winArabicToUtf8(s) | |
newName = sys.argv[1] | |
if newName[-4:]=='.txt': | |
newName = newName[:-4] | |
newName += '.utf8.txt' | |
file(newName, 'w').write(ws) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment