From f58497969cb69f46bf8672e51ea5765ebbcac18d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Wed, 14 Dec 2016 16:45:12 +0100 Subject: [PATCH] Refactor characters which should not be bothered into a whitelist --- normalisename.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/normalisename.py b/normalisename.py index 228faef..b942276 100644 --- a/normalisename.py +++ b/normalisename.py @@ -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(' ', '_')) -