Last active
September 8, 2016 02:24
-
-
Save spikeekips/0a80b1079e4660d50dded81e351f00a8 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
""" | |
# nfc2nfd.py | |
Simply convert nfc(ed) file to nfd(ed) file | |
Written by Spike^ekipS <spikeekips@gmail.com> | |
# Installation | |
1. save this gist to /usr/local/bin/nfc2nfd.py | |
1. run `$ chmod 755 /usr/local/bin/nfc2nfd.py | |
# Usage | |
If your filename is `input.txt`, | |
``` | |
$ cat input.txt | nfc2nfd.py | |
``` | |
or | |
``` | |
$ nfc2nfd.py input.txt | |
``` | |
""" | |
import sys | |
import select | |
import unicodedata | |
def usage(): | |
print 'Usage: %s [filename]' % sys.argv[0] | |
target = None | |
if select.select([sys.stdin, ], [], [], 0.0)[0]: | |
target = sys.stdin.read() | |
else: | |
try: | |
target = file(sys.argv[1]).read() | |
except IndexError: | |
pass | |
if target is None: | |
usage() | |
sys.exit(1) | |
print unicodedata.normalize('NFC', unicode(target, 'utf-8')).encode('utf-8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment