Skip to content

Instantly share code, notes, and snippets.

@asilachev
Created July 19, 2016 06:51
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 asilachev/94966243344f841d8f0b00aeb9ec6bd4 to your computer and use it in GitHub Desktop.
Save asilachev/94966243344f841d8f0b00aeb9ec6bd4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import argparse
import glob
import os
import sys
from transliterate import translit
def process_line(line):
return translit(line.decode('utf-8'), 'ru', reversed=True)
def main(argv):
parser = argparse.ArgumentParser(description='Transliterates file names')
parser.add_argument('-f', '--file',
help='a file for transliteration')
parser.add_argument('-w', '--wildcard',
help='Transliterates all files in current dir selected by wildcard')
args = parser.parse_args()
if not args.file and not args.wildcard:
parser.print_usage()
else:
if args.wildcard:
files = glob.glob(args.wildcard)
for f in files:
os.rename(f, process_line(f))
if args.file:
os.rename(args.file, process_line(args.file))
if __name__ == '__main__':
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment