Skip to content

Commit

Permalink
use string.punctuation and unicodedata
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisaaronland committed Aug 10, 2012
1 parent 384c83d commit 7558ff8
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions bin/utils.py
@@ -1,5 +1,7 @@
import os.path
import pprint import pprint
import os.path
import string
import unicodedata


def dumper(data): def dumper(data):
print pprint.pformat(data) print pprint.pformat(data)
Expand All @@ -18,23 +20,26 @@ def id2path(id):


return os.path.join(*parts) return os.path.join(*parts)


def clean_meta_name(name): def clean_meta_name(name, allow_punctuation=[]):

# sudo make me better


name = name.strip() name = name.strip()
name = name.replace(" ", "-")
name = name.replace("?", "")
name = name.replace("&", "")
name = name.replace(":", "")
name = name.replace("/", "-")
name = name.replace(",", "-")
name = name.replace("'", "-")
name = name.replace("(", "-")
name = name.replace(")", "")
name = name.replace("`", "")
name = name.replace("--", "-")
name = name.replace("..", ".")
name = name.lower() name = name.lower()

name = remove_accents(name)

for c in string.punctuation:


if c in allow_punctuation:
continue

name = name.replace(c, "")

name = name.replace(" ", "-")
name = name.replace("--", "-")

return name return name

def remove_accents(input_str):
nkfd_form = unicodedata.normalize('NFKD', unicode(input_str))
only_ascii = nkfd_form.encode('ASCII', 'ignore')
return only_ascii

0 comments on commit 7558ff8

Please sign in to comment.