mirror of
https://git.lecygnenoir.info/LecygneNoir/prismedia.git
synced 2025-10-04 09:59:16 +02:00
Simplify cleanString function to prepare python3 compatibility
This commit is contained in:
parent
3797c9a9f0
commit
2f40ef1826
1 changed files with 5 additions and 12 deletions
17
lib/utils.py
17
lib/utils.py
|
@ -3,9 +3,10 @@
|
||||||
|
|
||||||
from ConfigParser import RawConfigParser, NoOptionError, NoSectionError
|
from ConfigParser import RawConfigParser, NoOptionError, NoSectionError
|
||||||
from os.path import dirname, splitext, basename, isfile
|
from os.path import dirname, splitext, basename, isfile
|
||||||
|
import re
|
||||||
from os import devnull
|
from os import devnull
|
||||||
from subprocess import check_call, CalledProcessError, STDOUT
|
from subprocess import check_call, CalledProcessError, STDOUT
|
||||||
import unicodedata
|
import unidecode
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
### CATEGORIES ###
|
### CATEGORIES ###
|
||||||
|
@ -195,16 +196,8 @@ def upcaseFirstLetter(s):
|
||||||
|
|
||||||
|
|
||||||
def cleanString(toclean):
|
def cleanString(toclean):
|
||||||
toclean = toclean.split(' ')
|
toclean = toclean.decode('utf-8')
|
||||||
cleaned = ''
|
toclean = unidecode.unidecode(toclean)
|
||||||
for s in toclean:
|
cleaned = re.sub('[^A-Za-z0-9]+', '', toclean)
|
||||||
if s == '':
|
|
||||||
continue
|
|
||||||
strtoclean = unicodedata.normalize('NFKD', unicode (s, 'utf-8')).encode('ASCII', 'ignore')
|
|
||||||
strtoclean = ''.join(e for e in strtoclean if e.isalnum())
|
|
||||||
if strtoclean == '':
|
|
||||||
continue
|
|
||||||
strtoclean = upcaseFirstLetter(strtoclean)
|
|
||||||
cleaned = cleaned + strtoclean
|
|
||||||
|
|
||||||
return cleaned
|
return cleaned
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue