Created
July 19, 2016 06:51
-
-
Save asilachev/94966243344f841d8f0b00aeb9ec6bd4 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
#!/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