Skip to content

Instantly share code, notes, and snippets.

@ilius
Created August 25, 2015 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilius/b8021278215ac7bbb3fd to your computer and use it in GitHub Desktop.
Save ilius/b8021278215ac7bbb3fd to your computer and use it in GitHub Desktop.
#!/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