Skip to content

Instantly share code, notes, and snippets.

@korolr
Last active May 9, 2019 19:56
Show Gist options
  • Save korolr/8185beb8bfd3b3197ef9e210f3c8cb22 to your computer and use it in GitHub Desktop.
Save korolr/8185beb8bfd3b3197ef9e210f3c8cb22 to your computer and use it in GitHub Desktop.
translit.py
import os
from sys import argv
def latinizator(letter, dic):
for i, j in dic.items():
letter = letter.replace(i, j)
return letter
legend = {
' ':'_',
',':'',
'а':'a',
'б':'b',
'в':'v',
'г':'g',
'д':'d',
'е':'e',
'ё':'yo',
'ж':'zh',
'з':'z',
'и':'i',
'й':'y',
'к':'k',
'л':'l',
'м':'m',
'н':'n',
'о':'o',
'п':'p',
'р':'r',
'с':'s',
'т':'t',
'у':'u',
'ф':'f',
'х':'h',
'ц':'c',
'ч':'ch',
'ш':'sh',
'щ':'shch',
'ъ':'y',
'ы':'y',
'ь':"'",
'э':'e',
'ю':'yu',
'я':'ya',
'А':'A',
'Б':'B',
'В':'V',
'Г':'G',
'Д':'D',
'Е':'E',
'Ё':'Yo',
'Ж':'Zh',
'З':'Z',
'И':'I',
'Й':'Y',
'К':'K',
'Л':'L',
'М':'M',
'Н':'N',
'О':'O',
'П':'P',
'Р':'R',
'С':'S',
'Т':'T',
'У':'U',
'Ф':'F',
'Х':'H',
'Ц':'Ts',
'Ч':'Ch',
'Ш':'Sh',
'Щ':'Shch',
'Ъ':'Y',
'Ы':'Y',
'Ь':"'",
'Э':'E',
'Ю':'Yu',
'Я':'Ya',
}
for file_old in os.listdir('.'):
file_new = latinizator(file_old, legend)
if file_old != file_new:
print ('{0: <30}'.format(file_old), 'переименован в ', file_new )
os.rename(file_old, file_new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment