Refactor characters which should not be bothered into a whitelist

This commit is contained in:
Kjistóf 2016-12-14 16:45:12 +01:00 committed by Kristóf Tóth
parent 52dd5a2c22
commit f58497969c

View File

@ -3,16 +3,18 @@ from os import rename
from unidecode import unidecode
# whitespaces will be replaced
# dots are ok
# do not ruin previous work
# dashes are ok
whitelist = [' ', '.', '_', '-']
for file in argv[1:]:
rename(file,
unidecode
(
''.join(ch for ch in file
if ch.isalnum()
or ch is ' ' # whitespaces will be replaced
or ch is '.' # dots are ok
or ch is '_' # do not ruin previous work
or ch is '-') # dashes are ok
or ch in whitelist)
)
.replace(' ', '_'))